結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 0 ms
4,376 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 1 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,376 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 0 ms
4,376 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 24 ms
4,380 KB
testcase_18 AC 24 ms
4,376 KB
testcase_19 WA -
testcase_20 AC 24 ms
4,380 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 24 ms
4,380 KB
testcase_25 AC 24 ms
4,376 KB
testcase_26 AC 24 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 23 ms
4,376 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[i];
    }
    ans+=(long long)len-1;
  }

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