結果
問題 |
No.482 あなたの名は
|
ユーザー |
![]() |
提出日時 | 2017-02-10 22:26:53 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
RE
|
実行時間 | - |
コード長 | 467 bytes |
コンパイル時間 | 2,896 ms |
コンパイル使用メモリ | 157,776 KB |
実行使用メモリ | 9,856 KB |
最終ジャッジ日時 | 2024-12-28 05:55:28 |
合計ジャッジ時間 | 15,075 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 22 RE * 5 TLE * 1 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; int main(){ int n,k; cin>>n>>k; int d[n]; for(int i=0;i<n;i++) cin>>d[i]; for(int i=0;i<n;i++) d[i]--; int r=0; int u[n]; memset(u,0,sizeof(u)); for(int i=0;i<n;i++){ if(u[i]) continue; int t=0,c=i; while(!u[c]){ u[c]=1; c=d[c]; t++; } r+=t-1; } //cout<<r<<endl; if(r>k||(r-k)%2) cout<<"NO"<<endl; else cout<<"YES"<<endl; return 0; }