結果

問題 No.482 あなたの名は
ユーザー yomo3yomo3
提出日時 2020-04-05 21:12:43
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 733 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 176,864 KB
実行使用メモリ 13,576 KB
最終ジャッジ日時 2024-07-04 03:42:13
合計ジャッジ時間 3,802 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    cin.tie(0);ios::sync_with_stdio(false);

    ll N, K; cin >> N >> K;
    vector<int> D(N);
    unordered_map<int, int> m;
    rep(i, N) {
        cin >> D[i]; D[i]--;
        m[D[i]] = i;
    }

    int c = 0;
    rep(i, N) {
        if (D[i] != i) {
            D[m[i]] = D[i];
            m[D[i]] = m[i];
            D[i] = i;
            c++;
        }
    }
    bool ok = (c <= K && (c&1) == (K&1));
    cout << (ok ? "YES" : "NO") << endl;
}
0