結果

問題 No.482 あなたの名は
ユーザー k-mats
提出日時 2017-02-11 00:06:13
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 793 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 56,320 KB
実行使用メモリ 13,644 KB
最終ジャッジ日時 2024-12-29 07:50:05
合計ジャッジ時間 38,860 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12 WA * 1 TLE * 15
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

void solve() {
    int n, k;
    cin >> n >> k;

    int d[n];
    for (int i = 0; i < n; i++) {
        cin >> d[i];
    }

    int cnt = 0;

    for (int i = 0; i < n - 1; i++) {
        if (d[i] == i + 1) {
            continue;
        }

        for (int j = i + 1; j < n; j++) {
            if (d[j] == i + 1) {
                int tmp = d[i];
                d[i] = d[j];
                d[j] = tmp;
                cnt++;
                break;
            }
        }

        if (cnt > k) {
            cout << "NO" << endl;
            return;
        }
    }

    if ((k - cnt) % 2 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
}


int main(int argc, char *argv[]) {
    solve();

    return 0;
}
0