結果

問題 No.482 あなたの名は
ユーザー ronpooronpoo
提出日時 2023-10-31 12:53:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 154 ms / 2,000 ms
コード長 474 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 107,904 KB
最終ジャッジ日時 2023-10-31 12:53:55
合計ジャッジ時間 4,724 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,604 KB
testcase_01 AC 38 ms
53,604 KB
testcase_02 AC 38 ms
53,604 KB
testcase_03 AC 38 ms
53,604 KB
testcase_04 AC 40 ms
53,604 KB
testcase_05 AC 38 ms
53,604 KB
testcase_06 AC 38 ms
53,604 KB
testcase_07 AC 41 ms
55,652 KB
testcase_08 AC 40 ms
55,652 KB
testcase_09 AC 40 ms
55,652 KB
testcase_10 AC 41 ms
55,652 KB
testcase_11 AC 41 ms
55,652 KB
testcase_12 AC 40 ms
55,652 KB
testcase_13 AC 40 ms
55,652 KB
testcase_14 AC 40 ms
55,652 KB
testcase_15 AC 143 ms
107,644 KB
testcase_16 AC 138 ms
107,644 KB
testcase_17 AC 142 ms
107,644 KB
testcase_18 AC 142 ms
107,644 KB
testcase_19 AC 137 ms
107,644 KB
testcase_20 AC 135 ms
107,644 KB
testcase_21 AC 136 ms
107,644 KB
testcase_22 AC 137 ms
107,644 KB
testcase_23 AC 144 ms
107,644 KB
testcase_24 AC 139 ms
107,644 KB
testcase_25 AC 154 ms
107,644 KB
testcase_26 AC 137 ms
107,644 KB
testcase_27 AC 134 ms
107,644 KB
testcase_28 AC 133 ms
107,644 KB
testcase_29 AC 111 ms
107,904 KB
testcase_30 AC 38 ms
53,604 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

N, K = map(int, input().split())
D = list(map(int, input().split()))

comp = [-1] * N
cnt = 0
for i in range(N):
    if comp[i] != -1:
        continue
    cnt += 1
    j = i
    while comp[j] == -1:
        comp[j] = cnt
        j = D[j]-1

d = defaultdict(int)
for i in range(N):
    d[comp[i]] += 1

cnt = 0
for v in d.values():
    cnt += v-1

if cnt > K:
    print('NO')
elif (K-cnt) % 2 == 1:
    print('NO')
else:
    print('YES')
0