結果
| 問題 |
No.482 あなたの名は
|
| コンテスト | |
| ユーザー |
Dugong
|
| 提出日時 | 2017-03-16 21:22:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 25 ms / 2,000 ms |
| コード長 | 472 bytes |
| コンパイル時間 | 209 ms |
| コンパイル使用メモリ | 34,652 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-04 02:44:16 |
| 合計ジャッジ時間 | 1,699 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:16:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
16 | scanf("%lld %lld",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~~~~~
main.cpp:20:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
20 | scanf("%d",&d);
| ~~~~~^~~~~~~~~
ソースコード
#include<cstdio>
#include<algorithm>
using namespace std;
int a[200000];
bool used[200000];
int dfs(int x,int cnt){
used[x] = true;
if(used[a[x]]||x==a[x]) return cnt;
else return dfs(a[x],cnt+1);
}
int main(){
long long n,k,m = 0;
scanf("%lld %lld",&n,&k);
fill(used,used+n,false);
for(int i=0;i<n;i++){
int d;
scanf("%d",&d);
a[i] = d - 1;
}
for(int i=0;i<n;i++) m += dfs(i,0);
if(m<=k&&(k-m)%2==0) printf("YES\n");
else printf("NO\n");
return 0;
}
Dugong