結果

問題 No.482 あなたの名は
ユーザー nyan_nyan_farm
提出日時 2017-02-10 23:56:09
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 603 bytes
コンパイル時間 1,466 ms
コンパイル使用メモリ 158,620 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 20:23:16
合計ジャッジ時間 3,887 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    long long n,k;
    long long circle_num=0;
    cin>>n>>k;
    int room=n;
    int d[n],used[n];
    for(int i=0; i<n; i++){
        int in;
        cin>>in;
        in--;
        d[i]=in;
        used[i]=0;
    }
    for(int i=0; i<n; i++){
        if(!used[i]){
            int next=i;
            while(!used[next]){
                used[next]=1;
                next=d[next];
            }
            circle_num++;
        }
    }
    cout<<((k-room+circle_num >= 0 && (k-room+circle_num)%2 == 0)?("YES"):("NO"))<<endl;
    return 0;
}

0