結果

問題 No.482 あなたの名は
ユーザー tatuyan_edsontatuyan_edson
提出日時 2017-02-09 00:04:16
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 756 bytes
コンパイル時間 110 ms
コンパイル使用メモリ 25,316 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-26 17:39:35
合計ジャッジ時間 1,864 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 0 ms
4,376 KB
testcase_02 AC 0 ms
4,380 KB
testcase_03 AC 0 ms
4,376 KB
testcase_04 AC 0 ms
4,380 KB
testcase_05 WA -
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 0 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 WA -
testcase_10 AC 1 ms
4,376 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
4,376 KB
testcase_14 WA -
testcase_15 AC 24 ms
4,380 KB
testcase_16 AC 24 ms
4,380 KB
testcase_17 WA -
testcase_18 AC 24 ms
4,376 KB
testcase_19 AC 24 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 24 ms
4,380 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 24 ms
4,376 KB
testcase_25 WA -
testcase_26 AC 24 ms
4,376 KB
testcase_27 WA -
testcase_28 AC 25 ms
4,380 KB
testcase_29 AC 23 ms
4,380 KB
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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[i];
    }
    ans+=(long long)len-1;
  }

  if(k<ans) puts("NO");
  if((k-ans)%2==1) puts("NO");
  else puts("YES");
  free(data);
  free(flg);
  return 0;
}
0