結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー たこしたこし
提出日時 2015-11-04 14:59:34
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 1,362 bytes
コンパイル時間 500 ms
コンパイル使用メモリ 66,380 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-11 13:40:58
合計ジャッジ時間 17,944 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,512 KB
testcase_01 AC 2 ms
4,352 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,352 KB
testcase_04 AC 1 ms
4,352 KB
testcase_05 AC 2 ms
4,352 KB
testcase_06 AC 1 ms
4,352 KB
testcase_07 AC 2 ms
4,348 KB
testcase_08 AC 2 ms
4,372 KB
testcase_09 AC 2 ms
4,348 KB
testcase_10 AC 2 ms
4,352 KB
testcase_11 AC 109 ms
4,356 KB
testcase_12 AC 113 ms
4,352 KB
testcase_13 AC 108 ms
4,356 KB
testcase_14 AC 159 ms
4,368 KB
testcase_15 AC 12 ms
4,352 KB
testcase_16 AC 15 ms
4,372 KB
testcase_17 AC 16 ms
4,348 KB
testcase_18 AC 20 ms
4,348 KB
testcase_19 AC 24 ms
4,348 KB
testcase_20 AC 2 ms
4,348 KB
testcase_21 AC 3 ms
4,352 KB
testcase_22 AC 35 ms
4,356 KB
testcase_23 AC 19 ms
4,348 KB
testcase_24 AC 314 ms
4,348 KB
testcase_25 AC 217 ms
4,348 KB
testcase_26 AC 159 ms
4,352 KB
testcase_27 AC 2,460 ms
4,352 KB
testcase_28 AC 1,479 ms
4,352 KB
testcase_29 AC 1,377 ms
4,352 KB
testcase_30 AC 1,126 ms
4,352 KB
testcase_31 AC 1,094 ms
4,348 KB
testcase_32 AC 1,096 ms
4,352 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <queue>
#include <algorithm>
#include <cstring>

using namespace std;

typedef long long LL;

#define MAX_N 101
#define MAX_K 1001

int N, K;
int X[MAX_K], Y[MAX_K];

void Input(){

  cin >> N;
  cin >> K;

  for(int i = 0; i < K; i++){
    cin >> X[i] >> Y[i];
  }

}

bool ChangeFlag[MAX_N];
int List[2][MAX_N];

void ExecAmida(vector<int>& AmidaList){

  for(int k = 0; k < K; k++){
    int x = X[k], y = Y[k];
    x--; y--;
    swap(AmidaList[x], AmidaList[y]);
  }

}

int Solve(){

  vector<int> AmidaList;

  for(int i = 1; i <= N; i++){
    AmidaList.push_back(i);
    List[0][i-1] = i-1;
  }

  //MakeAmidaExec
  ExecAmida(AmidaList);

  vector<int> NextList;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j < N; j++){
      if(AmidaList[j] == i){
	NextList.push_back(j);
	break;
      }
    }
  }

  //Debug
  /*
  for(int i = 0; i < N; i++){
    cerr << i << "->" << NextList[i] << endl;
  }
  */

  int ret = 0;
  while(true){
    ret++;
    bool flag = true;
    for(int i = 0; i < N; i++){
      int nextPos = NextList[i];
      List[ret%2][nextPos] = List[(ret-1)%2][i];
      if(List[ret%2][nextPos] != nextPos){
	flag = false;
      }
    }
    if(flag)
      break;
  }

  return ret;

}

int main(){

  Input();

  cout << Solve() << endl;

  return 0;

}
0