結果

問題 No.482 あなたの名は
ユーザー neterukunneterukun
提出日時 2019-06-03 22:49:13
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 296 ms / 2,000 ms
コード長 332 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 29,672 KB
最終ジャッジ日時 2024-09-17 20:38:52
合計ジャッジ時間 6,328 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
d = list(map(int, input().split()))

visited = [False]*n

ans = 0
for i in range(n):
    j = i
    cnt = 0
    while not visited[j]:
        visited[j] = True
        j = d[j] - 1
        cnt += 1
    ans += max(cnt - 1, 0)

if ans <= k and (k - ans) % 2 == 0:
    print("YES")
else:
    print("NO")
0