結果
| 問題 | No.101 ぐるぐる!あみだくじ! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-22 08:58:10 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 5,000 ms |
| コード長 | 670 bytes |
| コンパイル時間 | 957 ms |
| コンパイル使用メモリ | 72,680 KB |
| 最終ジャッジ日時 | 2025-01-13 06:51:55 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include <iostream>
#include <numeric>
#include <vector>
using lint = long long;
void solve() {
int n, k;
std::cin >> n >> k;
std::vector<int> xs(n);
std::iota(xs.begin(), xs.end(), 0);
while (k--) {
int x, y;
std::cin >> x >> y;
std::swap(xs[--x], xs[--y]);
}
lint ans = 1;
for (int i = 0; i < n; ++i) {
int j = xs[i];
int cnt = 1;
while (j != i) {
j = xs[j];
++cnt;
}
ans = std::lcm(ans, cnt);
}
std::cout << ans << "\n";
}
int main() {
std::cin.tie(nullptr);
std::ios::sync_with_stdio(false);
solve();
return 0;
}