結果
問題 | No.100 直列あみだくじ |
ユーザー |
![]() |
提出日時 | 2025-03-20 18:38:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 49 ms / 5,000 ms |
コード長 | 685 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,340 KB |
実行使用メモリ | 55,604 KB |
最終ジャッジ日時 | 2025-03-20 18:38:33 |
合計ジャッジ時間 | 3,485 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
n = int(input()) a = list(map(int, input().split())) visited = [False] * (n + 1) cycle_lengths = [] for i in range(1, n + 1): if not visited[i]: length = 0 current = i while not visited[current]: visited[current] = True current = a[current - 1] # since a is 1-based in the problem description length += 1 cycle_lengths.append(length) from collections import defaultdict counter = defaultdict(int) for l in cycle_lengths: counter[l] += 1 possible = True for l in counter: if l % 2 == 0: if counter[l] % 2 != 0: possible = False break print("Yes" if possible else "No")