結果
問題 |
No.101 ぐるぐる!あみだくじ!
|
ユーザー |
|
提出日時 | 2014-12-11 23:48:10 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 610 bytes |
コンパイル時間 | 529 ms |
コンパイル使用メモリ | 42,752 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-11 20:47:59 |
合計ジャッジ時間 | 1,480 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 37 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:9:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 9 | scanf("%d%d",&N,&K); | ~~~~~^~~~~~~~~~~~~~ main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | scanf("%d%d",&a,&b),a--,b--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <vector> #include <algorithm> #include <numeric> #include <cstdio> using namespace std; int gcd(int x,int y){return y?gcd(y,x%y):x;} int main(){ int N,K; scanf("%d%d",&N,&K); vector<int>shuf(N); iota(shuf.begin(),shuf.end(),0); vector<int>orig=shuf; for(int i=0;i<K;i++){ int a,b; scanf("%d%d",&a,&b),a--,b--; swap(shuf[a],shuf[b]); } vector<int>elem(N); for(int i=0;i<N;i++){ int x=shuf[i],c=1; for(;x!=i;c++)x=shuf[x]; elem[i]=c; } for(int i=elem.size()-1;i>0;i--){ elem[i-1]=elem[i-1]/gcd(elem[i-1],elem[i])*elem[i]; } printf("%d\n",elem[0]); }