結果
問題 |
No.482 あなたの名は
|
ユーザー |
![]() |
提出日時 | 2017-02-08 23:51:45 |
言語 | C90 (gcc 12.3.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 571 bytes |
コンパイル時間 | 237 ms |
コンパイル使用メモリ | 21,120 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-25 17:00:44 |
合計ジャッジ時間 | 2,709 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 WA * 10 |
コンパイルメッセージ
main.c: In function ‘main’: main.c:11:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 11 | scanf("%d%lld",&n,&k); | ^~~~~~~~~~~~~~~~~~~~~ main.c:15:21: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 15 | for(i=1;i<=n;i++) scanf("%d",&data[i]); | ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h> #include<stdlib.h> int main(void){ int n,i; long long k,ans; int *d,*data; char *flg; int len,next; scanf("%d%lld",&n,&k); data=(int *)calloc(n+1,sizeof(int)); flg=(char *)calloc(n+1,sizeof(char)); for(i=1;i<=n;i++) scanf("%d",&data[i]); ans=0; for(i=1;i<=n;i++){ if(flg[i]) continue; next=i; len=0; while(flg[next]==0){ flg[next]=1; len++; next=data[i]; } ans+=(long long)len-1; } if(k<ans) puts("NO"); else puts((k-ans)%2?"NO":"YES"); free(data); free(flg); return 0; }