結果

問題 No.472 平均順位
ユーザー akakimidoriakakimidori
提出日時 2017-05-06 03:16:00
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 960 bytes
コンパイル時間 975 ms
コンパイル使用メモリ 26,256 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 13:10:04
合計ジャッジ時間 2,668 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 1 ms
4,352 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 1 ms
4,352 KB
testcase_04 AC 1 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 0 ms
4,352 KB
testcase_07 AC 1 ms
4,356 KB
testcase_08 AC 2 ms
4,352 KB
testcase_09 AC 5 ms
4,352 KB
testcase_10 AC 7 ms
4,348 KB
testcase_11 AC 18 ms
4,352 KB
testcase_12 AC 16 ms
4,356 KB
testcase_13 AC 78 ms
4,348 KB
testcase_14 AC 87 ms
4,348 KB
testcase_15 AC 78 ms
4,352 KB
testcase_16 AC 54 ms
4,352 KB
testcase_17 AC 33 ms
4,348 KB
testcase_18 AC 4 ms
4,352 KB
testcase_19 AC 44 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define POS(i,j) ((i)*n+(j))

void initMAX(int *array,int n){
  const int t=~(1<<31);
  int i;
  for(i=0;i<n;i++){
    array[i]=t;
  }
  return;
}

void run(void){
  const int f=4;
  int n,p;
  scanf("%d%d",&n,&p);
  int *a=(int *)malloc(sizeof(int)*4*n);
  int i;
  for(i=0;i<n;i++){
    scanf("%d%d%d",a+POS(0,i),a+POS(1,i),a+POS(2,i));
    a[POS(3,i)]=1;
  }

  int *now=(int *)calloc(3*n+1,sizeof(int));
  int *next=(int *)calloc(3*n+1,sizeof(int));
  for(i=0;i<f;i++){
    now[i]=a[POS(i,0)];
  }

  for(i=1;i<n;i++){
    initMAX(next,p+1);
    int j;
    for(j=MAX(0,p-3*(n-i));j<=MIN(p,3*i);j++){
      int k;
      for(k=0;k<f;k++){
        next[j+k]=MIN(next[j+k],now[j]+a[POS(k,i)]);
      }
    }
    int *swap=next;
    next=now;
    now=swap;
  }

  printf("%.5lf\n",(double)now[p]/n);

  return;
}

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