結果

問題 No.100 直列あみだくじ
ユーザー titia
提出日時 2025-06-19 02:52:37
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 60 ms / 5,000 ms
コード長 604 bytes
コンパイル時間 414 ms
コンパイル使用メモリ 12,288 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2025-06-19 02:52:41
合計ジャッジ時間 3,816 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 45
権限があれば一括ダウンロードができます

ソースコード

diff #

# 解説を見た。なるほど。これは思いつけるべきだったか。

import sys
input = sys.stdin.readline

N=int(input())
A=list(map(int,input().split()))

for i in range(N):
    A[i]-=1

USE=[0]*N
X=[0]*(N+1)

for i in range(N):
    if USE[i]==1:
        continue

    now=i
    USE[i]=1
    count=1

    while True:
        now=A[now]
        if USE[now]==1:
            break
        USE[now]=1
        count+=1

    #print(USE,count)

    if count%2==0:
        X[count]+=1

flag=1

for i in range(N+1):
    if X[i]%2==1:
        flag=0

if flag:
    print("Yes")
else:
    print("No")
0