結果

問題 No.482 あなたの名は
ユーザー rpy3cpprpy3cpp
提出日時 2017-03-26 01:17:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 624 bytes
コンパイル時間 119 ms
コンパイル使用メモリ 10,904 KB
実行使用メモリ 31,780 KB
最終ジャッジ日時 2023-09-20 10:50:14
合計ジャッジ時間 4,053 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,908 KB
testcase_01 AC 15 ms
7,816 KB
testcase_02 AC 16 ms
7,756 KB
testcase_03 AC 15 ms
7,824 KB
testcase_04 AC 15 ms
7,800 KB
testcase_05 AC 16 ms
7,804 KB
testcase_06 AC 16 ms
7,900 KB
testcase_07 AC 16 ms
8,256 KB
testcase_08 AC 15 ms
7,900 KB
testcase_09 AC 16 ms
7,940 KB
testcase_10 AC 16 ms
7,948 KB
testcase_11 AC 16 ms
7,860 KB
testcase_12 AC 16 ms
8,324 KB
testcase_13 AC 16 ms
7,812 KB
testcase_14 AC 15 ms
7,948 KB
testcase_15 AC 139 ms
31,648 KB
testcase_16 AC 144 ms
31,676 KB
testcase_17 AC 143 ms
31,680 KB
testcase_18 AC 143 ms
31,596 KB
testcase_19 AC 142 ms
31,780 KB
testcase_20 AC 140 ms
31,708 KB
testcase_21 AC 142 ms
31,532 KB
testcase_22 AC 143 ms
31,520 KB
testcase_23 AC 143 ms
31,596 KB
testcase_24 AC 145 ms
31,640 KB
testcase_25 AC 145 ms
31,684 KB
testcase_26 AC 144 ms
31,668 KB
testcase_27 AC 145 ms
31,596 KB
testcase_28 AC 145 ms
31,604 KB
testcase_29 AC 112 ms
31,644 KB
testcase_30 AC 16 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    N, K = map(int, input().split())
    Ds = list(map(int, input().split()))
    return N, K, Ds

def solve(N, K, Ds):
    group = list(range(N))
    Ds = [d - 1 for d in Ds]
    n_groups = 0
    for v in range(N):
        if group[v] != v:
            continue
        n_groups += 1
        u = v
        while Ds[u] != v:
            u = Ds[u]
            group[u] = v
    min_steps = N - n_groups
    if K < min_steps:
        return False
    elif (K - min_steps) % 2:
        return False
    else:
        return True

N, K, Ds = read_data()
if solve(N, K, Ds):
    print('YES')
else:
    print('NO')
0