結果
| 問題 | No.101 ぐるぐる!あみだくじ! |
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-12-20 19:35:30 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 5,000 ms |
| コード長 | 646 bytes |
| コンパイル時間 | 1,716 ms |
| コンパイル使用メモリ | 196,148 KB |
| 最終ジャッジ日時 | 2025-01-06 19:45:08 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
//INSERT ABOVE HERE
signed main(){
Int n,k;
cin>>n>>k;
vector<Int> v(n);
iota(v.begin(),v.end(),0);
for(Int i=0;i<k;i++){
Int x,y;
cin>>x>>y;
x--;y--;
swap(v[x],v[y]);
}
Int ans=1;
vector<Int> used(n,0);
for(Int i=0;i<n;i++){
if(used[i]) continue;
Int j=i,cnt=0;
while(!used[j]) used[j]=1,j=v[j],cnt++;
ans*=cnt/__gcd(ans,cnt);
}
cout<<ans<<endl;
return 0;
}
beet