結果

問題 No.482 あなたの名は
ユーザー treeone
提出日時 2017-02-10 22:43:46
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 808 bytes
コンパイル時間 1,449 ms
コンパイル使用メモリ 161,364 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-12-28 08:02:30
合計ジャッジ時間 3,882 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 17 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int n, k;
    cin >> n >> k;
    vector<int> d(n);
    int cnt = 0;
    int cnt2 = 0;
    rep(i, 0, n){
        cin >> d[i];
    }
    rep(i, 0, n){
        if(d[i] != i + 1){
            cnt++;
            if(d[d[i] - 1] == i + 1){
                cnt2++;
            }
        }
    }
    cnt2 /= 2;
    // cout << cnt << cnt2 << endl;
    if(cnt > 0) cnt--;
    if(cnt2 > 1) cnt -= cnt2 - 1;
    bool f = true;
    if(cnt > k) f = false;
    if(cnt < k && (k - cnt) % 2 == 1) f = false;
    cout << (f ? "YES" : "NO") << endl;
}
0