結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,780 KB
testcase_01 AC 14 ms
7,896 KB
testcase_02 AC 14 ms
7,872 KB
testcase_03 AC 14 ms
7,816 KB
testcase_04 AC 14 ms
7,792 KB
testcase_05 AC 14 ms
7,868 KB
testcase_06 AC 14 ms
7,896 KB
testcase_07 AC 16 ms
8,216 KB
testcase_08 AC 15 ms
7,892 KB
testcase_09 AC 15 ms
7,928 KB
testcase_10 AC 15 ms
7,816 KB
testcase_11 AC 16 ms
8,252 KB
testcase_12 AC 15 ms
8,340 KB
testcase_13 AC 15 ms
7,784 KB
testcase_14 AC 15 ms
7,732 KB
testcase_15 AC 248 ms
40,012 KB
testcase_16 AC 256 ms
40,100 KB
testcase_17 AC 261 ms
40,036 KB
testcase_18 AC 250 ms
39,972 KB
testcase_19 AC 245 ms
40,132 KB
testcase_20 AC 251 ms
39,956 KB
testcase_21 AC 258 ms
40,056 KB
testcase_22 AC 259 ms
40,156 KB
testcase_23 AC 258 ms
40,020 KB
testcase_24 AC 254 ms
40,148 KB
testcase_25 AC 247 ms
40,168 KB
testcase_26 AC 257 ms
40,160 KB
testcase_27 AC 253 ms
40,148 KB
testcase_28 AC 248 ms
39,956 KB
testcase_29 AC 240 ms
39,200 KB
testcase_30 AC 15 ms
7,732 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, d_i in enumerate(d):
    e[d_i] = i

used_indices = set()
swap_times = list()

for i in range(n):
    index = i
    swap_time = -1

    while index not in used_indices:
        used_indices.add(index)
        index = e[index]
        swap_time += 1

    if swap_time > 0:
        swap_times.append(swap_time)

total_swap_time = sum(swap_times)

if (k - total_swap_time) % 2 == 0 and k >= total_swap_time:
    print('YES')
else:
    print('NO')
0