結果

問題 No.482 あなたの名は
ユーザー Naco
提出日時 2019-10-25 15:22:36
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 564 bytes
コンパイル時間 1,621 ms
コンパイル使用メモリ 166,496 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-07-19 19:35:00
合計ジャッジ時間 4,392 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 3
other WA * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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