結果

問題 No.482 あなたの名は
ユーザー phspls
提出日時 2020-04-12 01:47:46
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 57 ms / 2,000 ms
コード長 662 bytes
コンパイル時間 1,508 ms
コンパイル使用メモリ 168,284 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-19 20:20:51
合計ジャッジ時間 3,906 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define llong long long

int swapping(vector<int> &d) {
    int cnt = 0;
    rep(i, d.size()) {
        if(d[i] == i) continue;
        while(true) {
            swap(d[i], d[d[i]]);
            cnt += 1;
            if(d[i] == i) break;
        }
    }
    return cnt;
}

int main() {
    llong n, k;
    cin >> n >> k;
    vector<int> d(n);
    rep(i, n) {
        int val;
        cin >> val;
        d[i] = val -1;
    }

    llong cnt = swapping(d);
    if(cnt <= k && (k-cnt) % 2 == 0) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
}
0