結果

問題 No.482 あなたの名は
ユーザー はむ吉🐹はむ吉🐹
提出日時 2017-02-11 14:01:42
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 177 ms / 2,000 ms
コード長 508 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 10,928 KB
実行使用メモリ 38,488 KB
最終ジャッジ日時 2023-08-28 16:21:21
合計ジャッジ時間 4,427 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,924 KB
testcase_01 AC 16 ms
7,808 KB
testcase_02 AC 15 ms
7,864 KB
testcase_03 AC 16 ms
7,856 KB
testcase_04 AC 16 ms
7,856 KB
testcase_05 AC 15 ms
7,964 KB
testcase_06 AC 15 ms
7,820 KB
testcase_07 AC 16 ms
8,372 KB
testcase_08 AC 16 ms
7,816 KB
testcase_09 AC 16 ms
7,788 KB
testcase_10 AC 16 ms
7,872 KB
testcase_11 AC 16 ms
8,444 KB
testcase_12 AC 17 ms
8,308 KB
testcase_13 AC 16 ms
7,792 KB
testcase_14 AC 22 ms
7,876 KB
testcase_15 AC 169 ms
38,332 KB
testcase_16 AC 175 ms
38,316 KB
testcase_17 AC 166 ms
38,488 KB
testcase_18 AC 173 ms
38,320 KB
testcase_19 AC 167 ms
38,348 KB
testcase_20 AC 163 ms
38,336 KB
testcase_21 AC 169 ms
38,460 KB
testcase_22 AC 173 ms
38,452 KB
testcase_23 AC 163 ms
38,444 KB
testcase_24 AC 177 ms
38,320 KB
testcase_25 AC 167 ms
38,396 KB
testcase_26 AC 165 ms
38,396 KB
testcase_27 AC 161 ms
38,364 KB
testcase_28 AC 153 ms
38,476 KB
testcase_29 AC 138 ms
38,372 KB
testcase_30 AC 16 ms
7,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/usr/bin/env python3


def judge(n, k, ds):
    ps = {d: i for i, d in enumerate(ds)}
    c = 0
    for i in range(n):
        if ds[i] != i:
            j = ps[i]
            ds[i], ds[j] = ds[j], ds[i]
            ps[ds[i]] = i
            ps[ds[j]] = j
            c += 1
    return c <= k and (c + k) % 2 == 0


def main():
    n, k = (int(x) for x in input().split())
    ds = [int(x) - 1 for x in input().split()]
    print("YES" if judge(n, k, ds) else "NO")


if __name__ == '__main__':
    main()
0