結果

問題 No.100 直列あみだくじ
ユーザー maspy
提出日時 2020-01-01 18:30:51
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 31 ms / 5,000 ms
コード長 647 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-11-22 13:24:41
合計ジャッジ時間 3,109 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・巡回置換の長さ
・2n+1 -> 2n+1
・2n -> n, n
・結局、偶数は同数ずつないといけないというのが条件
"""

N,*A = map(int,read().split())

A = [0] + A

period = [0] * (N+1)
for i,x in enumerate(A):
    p = 0
    y = x
    while True:
        y = A[y]
        p += 1
        if y == x:
            break
    period[i] = p

counter = [0] * (N+10)
for x in period[1:]:
    counter[x] += 1

answer = 'Yes'
for i in range(2,N+10,2):
    if (counter[i]//i) % 2 != 0:
        answer = 'No'

print(answer)
0