結果

問題 No.101 ぐるぐる!あみだくじ!
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-27 18:41:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 39 ms / 5,000 ms
コード長 503 bytes
コンパイル時間 365 ms
コンパイル使用メモリ 82,364 KB
実行使用メモリ 55,580 KB
最終ジャッジ日時 2024-04-09 18:23:51
合計ジャッジ時間 3,258 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,584 KB
testcase_01 AC 39 ms
55,580 KB
testcase_02 AC 37 ms
53,824 KB
testcase_03 AC 36 ms
53,120 KB
testcase_04 AC 36 ms
53,208 KB
testcase_05 AC 39 ms
54,920 KB
testcase_06 AC 37 ms
52,520 KB
testcase_07 AC 38 ms
53,552 KB
testcase_08 AC 37 ms
53,388 KB
testcase_09 AC 38 ms
52,948 KB
testcase_10 AC 38 ms
53,028 KB
testcase_11 AC 39 ms
54,636 KB
testcase_12 AC 39 ms
53,268 KB
testcase_13 AC 38 ms
55,356 KB
testcase_14 AC 38 ms
53,264 KB
testcase_15 AC 39 ms
53,496 KB
testcase_16 AC 39 ms
54,084 KB
testcase_17 AC 38 ms
54,024 KB
testcase_18 AC 38 ms
53,736 KB
testcase_19 AC 38 ms
54,004 KB
testcase_20 AC 37 ms
53,148 KB
testcase_21 AC 38 ms
53,384 KB
testcase_22 AC 37 ms
54,500 KB
testcase_23 AC 39 ms
54,148 KB
testcase_24 AC 38 ms
53,884 KB
testcase_25 AC 39 ms
54,276 KB
testcase_26 AC 39 ms
54,372 KB
testcase_27 AC 39 ms
54,644 KB
testcase_28 AC 38 ms
53,308 KB
testcase_29 AC 39 ms
54,064 KB
testcase_30 AC 38 ms
53,820 KB
testcase_31 AC 39 ms
54,736 KB
testcase_32 AC 38 ms
53,344 KB
testcase_33 AC 39 ms
54,840 KB
testcase_34 AC 36 ms
52,412 KB
testcase_35 AC 37 ms
53,620 KB
testcase_36 AC 37 ms
52,472 KB
testcase_37 AC 38 ms
53,764 KB
testcase_38 AC 38 ms
53,004 KB
testcase_39 AC 37 ms
52,868 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import gcd
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)

ans = 1
for x in loop:
    g = gcd(ans, x)
    ans = ans // g * x
print(ans)
0