結果
問題 |
No.482 あなたの名は
|
ユーザー |
![]() |
提出日時 | 2017-02-10 22:28:57 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 69 ms / 2,000 ms |
コード長 | 492 bytes |
コンパイル時間 | 1,671 ms |
コンパイル使用メモリ | 159,400 KB |
実行使用メモリ | 6,656 KB |
最終ジャッジ日時 | 2024-12-29 19:02:09 |
合計ジャッジ時間 | 3,855 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define int long long signed 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; }