結果

問題 No.482 あなたの名は
ユーザー teketeke5000
提出日時 2017-08-25 15:03:47
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 66 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 1,370 ms
コンパイル使用メモリ 160,372 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-15 15:40:40
合計ジャッジ時間 4,423 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N,K;
ll cnt = 0;

void swap(ll *a, ll *b) {
    ll tmp = *a;
    *a = *b;
    *b = tmp;
}

int main(void) {
    cin >> N >> K;
    vector<ll> D(N+1);
    for (ll i=1; i<=N; i++) cin >> D[i];
    for (ll i=1; i<=N; i++) {
        while(D[i] != i) {
            swap(D[i], D[D[i]]);
            cnt++;
        }
        if (cnt > K) {
            cout << "NO" << endl;
            return 0;
        }
    }
    if ((K - cnt) % 2 == 0) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}
0