結果
問題 | No.101 ぐるぐる!あみだくじ! |
ユーザー |
![]() |
提出日時 | 2020-11-18 16:12:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 447 bytes |
コンパイル時間 | 487 ms |
コンパイル使用メモリ | 63,880 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 09:04:10 |
合計ジャッジ時間 | 1,744 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> using namespace std; int N,K; int T[100]; long gcd(long a,long b){return b?gcd(b,a%b):a;} bool vis[100]; main() { cin>>N>>K; for(int i=0;i<N;i++)T[i]=i; for(int i=0;i<K;i++) { int x,y;cin>>x>>y; T[x-1]^=T[y-1]^=T[x-1]^=T[y-1]; } long ans=1; for(int i=0;i<N;i++) { if(vis[i])continue; int t=i,cnt=0; while(!vis[t]) { vis[t]=true; t=T[t]; cnt++; } ans=ans/gcd(ans,cnt)*cnt; } cout<<ans<<endl; }