結果

問題 No.482 あなたの名は
ユーザー kichirb3kichirb3
提出日時 2018-03-28 19:39:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 152 ms / 2,000 ms
コード長 883 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,008 KB
実行使用メモリ 39,368 KB
最終ジャッジ日時 2023-09-07 19:28:52
合計ジャッジ時間 4,272 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,832 KB
testcase_01 AC 14 ms
7,816 KB
testcase_02 AC 14 ms
7,868 KB
testcase_03 AC 13 ms
7,828 KB
testcase_04 AC 14 ms
7,792 KB
testcase_05 AC 14 ms
7,824 KB
testcase_06 AC 14 ms
7,868 KB
testcase_07 AC 14 ms
8,456 KB
testcase_08 AC 14 ms
7,872 KB
testcase_09 AC 14 ms
7,884 KB
testcase_10 AC 14 ms
7,804 KB
testcase_11 AC 15 ms
8,400 KB
testcase_12 AC 15 ms
8,420 KB
testcase_13 AC 16 ms
7,816 KB
testcase_14 AC 14 ms
7,824 KB
testcase_15 AC 149 ms
39,224 KB
testcase_16 AC 142 ms
39,308 KB
testcase_17 AC 142 ms
39,320 KB
testcase_18 AC 142 ms
39,232 KB
testcase_19 AC 148 ms
39,248 KB
testcase_20 AC 152 ms
39,368 KB
testcase_21 AC 146 ms
39,176 KB
testcase_22 AC 147 ms
39,316 KB
testcase_23 AC 146 ms
39,332 KB
testcase_24 AC 149 ms
39,196 KB
testcase_25 AC 148 ms
39,344 KB
testcase_26 AC 142 ms
39,252 KB
testcase_27 AC 145 ms
39,336 KB
testcase_28 AC 149 ms
39,340 KB
testcase_29 AC 123 ms
39,272 KB
testcase_30 AC 14 ms
7,924 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# -*- coding: utf-8 -*-
"""
No.482 あなたの名は
https://yukicoder.me/problems/no/482

"""
import sys
from sys import stdin
input = stdin.readline


def solve(N, K, D):
    num2pos = dict()            # 数字がリストのどこにあるか検索するための辞書
    D.insert(0, 0)
    for i, d in enumerate(D):
        num2pos[d] = i

    for i in range(1, N+1):
        if D[i] != i:
            K -= 1              # 能力を1回使って魂を入れ替え
            target_pos = num2pos[i]
            num2pos[D[i]] = target_pos
            num2pos[i] = i
            D[target_pos], D[i] = D[i], D[target_pos]

    if K < 0 or K % 2 != 0:
        return 'NO'
    return 'YES'


def main(args):
    N, K = map(int, input().split())
    D = [int(x) for x in input().split()]
    ans = solve(N, K, D)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
0