結果

問題 No.482 あなたの名は
ユーザー akakimidoriakakimidori
提出日時 2017-04-26 15:01:22
言語 C90
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 580 bytes
コンパイル時間 225 ms
コンパイル使用メモリ 25,072 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-11 13:49:08
合計ジャッジ時間 2,993 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>

typedef long long int ln;

void swap(int *array,int i,int j){
  int t=array[i];
  array[i]=array[j];
  array[j]=t;
  return;
}

void run(void){
  int n;
  ln k;
  scanf("%d%lld",&n,&k);

  if(n-1<=k){
    printf("YES\n");
    return;
  }

  int *d=(int *)malloc(sizeof(int)*(n+1));
  int i;
  for(i=1;i<=n;i++){
    scanf("%d",d+i);
  }

  int count=0;
  for(i=1;i<=n;i++){
    while(d[i]!=i){
      swap(d,i,d[i]);
      count++;
    }
  }
  printf("%s\n",count<=k?"YES":"NO");
  free(d);
  return;
}

int main(void){
  run();
  return 0;
}
0