結果

問題 No.482 あなたの名は
ユーザー akakimidori
提出日時 2017-04-26 15:01:22
言語 C90
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 580 bytes
コンパイル時間 387 ms
コンパイル使用メモリ 21,888 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-09-13 12:31:47
合計ジャッジ時間 2,559 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 16 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:16:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |   scanf("%d%lld",&n,&k);
      |   ^~~~~~~~~~~~~~~~~~~~~
main.c:26:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   26 |     scanf("%d",d+i);
      |     ^~~~~~~~~~~~~~~

ソースコード

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