結果

問題 No.370 道路の掃除
ユーザー HankHank
提出日時 2016-05-24 21:12:46
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 1 ms / 2,000 ms
コード長 743 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 26,660 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-04 19:38:54
合計ジャッジ時間 1,563 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(){
  int n, m, *d, *r, result=10000000;
  int i,j,buff,num;
  int left,right;
  
  scanf("%d %d",&n,&m);
  
  d=(int*)malloc(sizeof(int)*m);
  r=(int*)malloc(sizeof(int)*(m-n+1));
  for(i=0;i<m;i++){
    scanf("%d",&d[i]);
  }
  for(i=0;i<m-1;i++){
    buff=10000;
    for(j=i;j<m;j++){
      if(d[j]<buff){
	buff = d[j];
	num = j;
      }
    }
    buff = d[i];
    d[i]=d[num];
    d[num]=buff;
  }
  for(i=0;i<m-n+1;i++){
    (d[i]>0)?(left=0):(left = -d[i]);
    (d[i+n-1]<0)?(right=0):(right=d[i+n-1]);
    
    r[i]=fmin(2*left+right,2*right+left);
  
    }
  for(i=0;i<m-n+1;i++){
    if(r[i]<result)result=r[i];
  }
  printf("%d\n",result);
  
  free(d);
  return 0;
}
0