結果
問題 |
No.482 あなたの名は
|
ユーザー |
![]() |
提出日時 | 2017-02-10 23:24:56 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 852 bytes |
コンパイル時間 | 705 ms |
コンパイル使用メモリ | 57,816 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 05:01:37 |
合計ジャッジ時間 | 3,058 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 15 WA * 13 |
ソースコード
#include<iostream> #include<vector> #include<string> using namespace std; #define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++) #define rep(i,n) FOR((i),0,(n)) typedef long long ll; const int INF=1e9+7; const int MAX_N=2*1e5+5; int a[MAX_N]; bool used[MAX_N]; int dep(int now,int from){ used[now]=true; if(now==from)return 1; return dep(a[now],from)+1; } int main(){ fill(used,used+MAX_N,false); ll n,k; cin>>n>>k; ll ans=0; rep(i,n){ int x; cin>>x; if(x!=i+1)ans++; a[i+1]=x; } int max_d=0; rep(i,n){ if(!used[a[i]])max_d=max(max_d,dep(a[i],i)); } ans=ans/2+(ans%2); if(k<ans)cout<<"NO"<<endl; else if((k-ans)%2==0)cout<<"YES"<<endl; else if(max_d>=3)cout<<"YES"<<endl; else if(max_d==2){ if(k-ans-2>=0)cout<<"YES"<<endl; else cout<<"NO"<<endl; } else { if(k-ans-4>=0)cout<<"YES"<<endl; else cout<<"NO"<<endl; } }