結果
問題 |
No.101 ぐるぐる!あみだくじ!
|
ユーザー |
![]() |
提出日時 | 2015-10-02 00:44:49 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,064 bytes |
コンパイル時間 | 1,539 ms |
コンパイル使用メモリ | 162,680 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 19:02:04 |
合計ジャッジ時間 | 2,701 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 WA * 2 |
other | AC * 2 WA * 35 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:39:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long long int’ [-Wformat=] 39 | printf("%d ", cnt); | ~^ ~~~ | | | | int long long int | %lld
ソースコード
#include "bits/stdc++.h" using namespace std; #define int long long #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 lcm(int a, int b) { return a * b / gcd(a, b); } int N,K; signed main() { cin >> N>>K; vector<int> amida(N); REP(i,N) amida[i] = i; int x, y; REP(i,K) { cin >> x >> y; swap(amida[x-1], amida[y-1]); } 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; printf("%d ", cnt); } // 最小公倍数を求める int lcmc = 1; REP(i,N) { lcmc = lcm(lcmc, loop[i]); } cout << lcmc << endl; return 0; }