結果

問題 No.482 あなたの名は
ユーザー tsutajtsutaj
提出日時 2019-01-16 21:12:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 502 bytes
コンパイル時間 564 ms
コンパイル使用メモリ 69,236 KB
実行使用メモリ 4,808 KB
最終ジャッジ日時 2023-09-11 02:23:29
合計ジャッジ時間 2,806 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 60 ms
4,592 KB
testcase_16 AC 59 ms
4,600 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 60 ms
4,580 KB
testcase_20 WA -
testcase_21 AC 60 ms
4,540 KB
testcase_22 AC 60 ms
4,520 KB
testcase_23 AC 60 ms
4,592 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 5 ms
4,652 KB
testcase_28 AC 5 ms
4,516 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main() {
    int N, K; cin >> N >> K;
    vector<int> p(N), used(N);
    
    for(int i=0; i<N; i++) {
        cin >> p[i];
    }
    
    int sum = 0;
    for(int i=0; i<N; i++) {
        int cnt = 0, idx = i;
        for(; used[idx] == false; idx = p[idx]) used[idx] = true, cnt++;
        if(cnt > 0) sum += cnt - 1;
    }
    
    if(sum <= K and K % 2 == sum % 2) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
0