結果

問題 No.482 あなたの名は
ユーザー ntuda
提出日時 2024-01-27 14:33:48
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 411 bytes
コンパイル時間 232 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 108,040 KB
最終ジャッジ日時 2024-09-28 09:39:08
合計ジャッジ時間 4,813 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
D = list(map(int, input().split()))
nv = [False] * N
cnt2 = 0
for i in range(N):
    if nv[i]:
        continue
    cnt = 0
    nv[i] = True
    next = D[i] - 1
    while next != i:
        cnt += 1
        nv[next] = True
        next = D[next] - 1
    #print(i, nv)
    cnt2 += cnt
if K < cnt2:
    print("NO")
elif (K - cnt2) % 2 == 1:
    print("NO")
else:
    print("YES")
0