結果
| 問題 | No.101 ぐるぐる!あみだくじ! |
| コンテスト | |
| ユーザー |
yaoshimax
|
| 提出日時 | 2015-03-09 23:31:22 |
| 言語 | Python2 (2.7.18) |
| 結果 |
AC
|
| 実行時間 | 15 ms / 5,000 ms |
| コード長 | 548 bytes |
| コンパイル時間 | 456 ms |
| コンパイル使用メモリ | 6,944 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-24 17:00:42 |
| 合計ジャッジ時間 | 1,953 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
ソースコード
def gcd(a,b):
if b< a:
return gcd(b,a)
if b%a==0:
return a
return gcd(b%a,a)
N=int(raw_input())
K=int(raw_input())
a=[i+1 for i in range(N)]
for i in range(K):
x,y=map(int,raw_input().split())
a[x-1],a[y-1]=a[y-1],a[x-1]
ans = 1
for i in range(len(a)):
if a[i]!=-1 and a[i]!=i+1:
cnt=1
cur=i
while a[cur]!=i+1:
cnt+=1
tmp=cur
cur=a[cur]-1
a[tmp]=-1
a[cur]=-1
g= gcd(ans,cnt)
ans*=cnt/g
print ans
yaoshimax