保存されている過去のバージョンの一覧

2021年01月02日17時05分24秒

第三回 アルゴリズム実技検定 K問題 - コンテナの移動

Source

第三回 アルゴリズム実技検定
問題文

問題概要

省略

解法

省略

cLayversion 20201229-1)のコード

C++に変換後のコードはこちら

int N, F, T, X;

int res[2d5];
int under[2d5], top[2d5], bottom[2d5];

int solve(int n){
  if(res[n] >= 0) return res[n];
  return res[n] = solve(under[n]);
}

{
  int tmp;

  rd(N);
  rep(i,N) res[i] = under[i] = -1;
  rep(i,N) top[i] = bottom[i] = i;

  REP(rd_int()){
    rd(F--, T--, X--);
    tmp = top[F];
    top[F] = under[X];
    if(bottom[F] == X) bottom[F] = -1;
    under[X] = top[T];
    top[T] = tmp;
    if(bottom[T]==-1) bottom[T] = X;
  }

  rep(i,N) if(bottom[i] != -1) res[bottom[i]] = i;
  rep(i,N) solve(i);
  wtLn(res(N)+1);
}

Current time: 2024年04月16日23時03分55秒
Last modified: 2021年01月02日17時05分24秒 (by laycrs)
Tags: Competitive_Programming_Incomplete AtCoder
トップページに戻る

Logged in as: unknown user (not login)

ログイン: