結果

問題 No.482 あなたの名は
ユーザー k-matsk-mats
提出日時 2017-02-11 00:39:43
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 286 ms / 2,000 ms
コード長 458 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 10,976 KB
実行使用メモリ 40,464 KB
最終ジャッジ日時 2023-08-28 16:16:42
合計ジャッジ時間 6,051 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,788 KB
testcase_01 AC 15 ms
7,972 KB
testcase_02 AC 15 ms
7,988 KB
testcase_03 AC 14 ms
7,924 KB
testcase_04 AC 15 ms
7,984 KB
testcase_05 AC 15 ms
7,936 KB
testcase_06 AC 15 ms
7,860 KB
testcase_07 AC 15 ms
8,320 KB
testcase_08 AC 16 ms
8,024 KB
testcase_09 AC 15 ms
7,832 KB
testcase_10 AC 16 ms
7,864 KB
testcase_11 AC 15 ms
8,372 KB
testcase_12 AC 16 ms
8,404 KB
testcase_13 AC 16 ms
7,820 KB
testcase_14 AC 15 ms
7,868 KB
testcase_15 AC 281 ms
40,420 KB
testcase_16 AC 282 ms
40,280 KB
testcase_17 AC 274 ms
40,420 KB
testcase_18 AC 284 ms
40,288 KB
testcase_19 AC 281 ms
40,428 KB
testcase_20 AC 272 ms
40,316 KB
testcase_21 AC 273 ms
40,292 KB
testcase_22 AC 286 ms
40,408 KB
testcase_23 AC 276 ms
40,464 KB
testcase_24 AC 284 ms
40,420 KB
testcase_25 AC 277 ms
40,440 KB
testcase_26 AC 280 ms
40,352 KB
testcase_27 AC 279 ms
40,448 KB
testcase_28 AC 284 ms
40,360 KB
testcase_29 AC 255 ms
39,140 KB
testcase_30 AC 15 ms
7,828 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = [int(i) for i in input().split()]
d = [int(i) - 1 for i in input().split()]

e = [0 for i in range(n)]
for i, dd in enumerate(d):
    e[dd] = i

used_indices = set()
hoge = list()

for i in range(n):
    x = i
    y = 0

    while x not in used_indices:
        used_indices.add(x)
        x = e[x]
        y += 1
    if y > 0:
        hoge.append(y)

x = sum(a - 1 for a in hoge)

if x % 2 == k % 2 and x <= k:
    print('YES')
else:
    print('NO')
0