結果
| 問題 |
No.482 あなたの名は
|
| ユーザー |
tatuyan_edson
|
| 提出日時 | 2017-02-09 00:10:17 |
| 言語 | C90 (gcc 12.3.0) |
| 結果 |
AC
|
| 実行時間 | 28 ms / 2,000 ms |
| コード長 | 744 bytes |
| コンパイル時間 | 350 ms |
| コンパイル使用メモリ | 21,504 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 19:00:08 |
| 合計ジャッジ時間 | 1,981 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 28 |
コンパイルメッセージ
main.c: In function ‘main’:
main.c:21:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
21 | scanf("%d%lld",&n,&k);
| ^~~~~~~~~~~~~~~~~~~~~
main.c:25:21: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
25 | for(i=1;i<=n;i++) scanf("%d",&data[i]);
| ^~~~~~~~~~~~~~~~~~~~
ソースコード
#include<stdio.h>
#include<stdlib.h>
int isprime(long long n){
long long i;
if(n<1 || (n!=2 && n%2==0)) return 0;
if(n==2) return 1;
for(i=3;i*i<=n;i++){
if(n%i==0) return 0;
}
return 1;
}
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[next];
}
ans+=(long long)len-1;
}
if(k<ans || (k-ans)%2==1) puts("NO");
else puts("YES");
free(data);
free(flg);
return 0;
}
tatuyan_edson