結果
問題 |
No.101 ぐるぐる!あみだくじ!
|
ユーザー |
![]() |
提出日時 | 2015-10-02 00:27:59 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,024 bytes |
コンパイル時間 | 1,493 ms |
コンパイル使用メモリ | 162,032 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 19:01:52 |
合計ジャッジ時間 | 2,410 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 34 WA * 3 |
ソースコード
#include "bits/stdc++.h" using namespace std; #define REP(i, n) for(int i=0; i<(n); i++) int gcd(int a, int b) { if (!b) return a; return gcd(b, a%b); } int N,K; signed main() { cin >> N>>K; vector<int> amida(N); REP(i,N) amida[i] = i; vector<int> x(K); int y; REP(i,K) { cin >> x[i] >> y; swap(amida[x[i]-1], amida[x[i]]); } int cnt = 0; vector<int> tmp(N); vector<int> loop(N, 0); REP(i,N) tmp[i] = i; while(true) { cnt++; vector<int> tmp2(N); REP(i,N) { tmp2[i] = tmp[amida[i]]; } bool isok = true; REP(i,N) { if (loop[i] == 0 && tmp2[i] == i) { loop[i] = cnt; } if (loop[i] == 0) isok = false; } if (isok) break; tmp = tmp2; } // 最小公倍数を求める int lcmc = 1; REP(i,N) { int g = gcd(lcmc, loop[i]); lcmc = lcmc * loop[i] / g; } cout << lcmc << endl; return 0; }