結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー data9824data9824
提出日時 2015-06-23 09:43:28
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 790 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 65,564 KB
実行使用メモリ 7,420 KB
最終ジャッジ日時 2023-09-22 00:09:20
合計ジャッジ時間 19,008 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 112 ms
4,376 KB
testcase_12 AC 110 ms
4,376 KB
testcase_13 AC 108 ms
4,380 KB
testcase_14 AC 156 ms
4,380 KB
testcase_15 AC 12 ms
4,376 KB
testcase_16 AC 15 ms
4,380 KB
testcase_17 AC 17 ms
4,380 KB
testcase_18 AC 20 ms
4,380 KB
testcase_19 AC 24 ms
4,380 KB
testcase_20 AC 3 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 36 ms
4,380 KB
testcase_23 AC 19 ms
4,376 KB
testcase_24 AC 310 ms
4,380 KB
testcase_25 AC 212 ms
4,380 KB
testcase_26 AC 153 ms
4,376 KB
testcase_27 AC 2,397 ms
4,376 KB
testcase_28 AC 1,458 ms
4,376 KB
testcase_29 AC 1,350 ms
4,376 KB
testcase_30 AC 1,096 ms
4,380 KB
testcase_31 AC 1,073 ms
4,376 KB
testcase_32 AC 1,060 ms
4,376 KB
testcase_33 TLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

bool isOrdered(const vector<int>& positions) {
	for (size_t i = 0; i < positions.size(); ++i) {
		if (positions[i] != i) {
			return false;
		}
	}
	return true;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> x(k), y(k);
	for (int i = 0; i < k; ++i) {
		cin >> x[i] >> y[i];
	}
	vector<int> positions(n);
	for (int i = 0; i < n; ++i) {
		positions[i] = i;
	}
	for (int i = 0; i < k; ++i) {
		swap(positions[x[i] - 1], positions[y[i] - 1]);
	}
	int result = 1;
	vector<int> values(positions);
	vector<int> newValues(n);
	while (!isOrdered(values)) {
		for (int i = 0; i < n; ++i) {
			newValues[i] = values[positions[i]];
		}
		values = newValues;
		++result;
	}
	cout << result << endl;
	return 0;
}
0