結果
問題 | No.101 ぐるぐる!あみだくじ! |
ユーザー |
![]() |
提出日時 | 2020-12-26 23:53:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 594 bytes |
コンパイル時間 | 239 ms |
コンパイル使用メモリ | 81,776 KB |
実行使用メモリ | 54,996 KB |
最終ジャッジ日時 | 2024-09-25 03:50:12 |
合計ジャッジ時間 | 3,403 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 WA * 29 |
ソースコード
import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) N = int(input()) *num, = range(N) K = int(input()) for _ in range(K): x, y = map(int, input().split()) y -= 2 num[x], num[y] = num[y], num[x] seen = [0] * N loop = [] for i in range(N): cnt = 0 while not seen[i]: seen[i] = 1 cnt += 1 i = num[i] if cnt: loop.append(cnt) if not loop: print(1) else: from math import gcd g = 0 for x in loop: g = gcd(g, x) ans = 1 for x in loop: ans *= x // g ans *= g print(ans)