結果

問題 No.482 あなたの名は
ユーザー tatuyan_edsontatuyan_edson
提出日時 2017-02-09 00:10:17
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 744 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 25,168 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 15:38:18
合計ジャッジ時間 2,147 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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

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