結果

問題 No.108 トリプルカードコンプ
ユーザー akakimidoriakakimidori
提出日時 2017-06-04 00:11:05
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 728 bytes
コンパイル時間 361 ms
コンパイル使用メモリ 23,704 KB
実行使用メモリ 8,484 KB
最終ジャッジ日時 2023-10-22 03:10:11
合計ジャッジ時間 1,094 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,348 KB
testcase_01 AC 0 ms
4,348 KB
testcase_02 AC 0 ms
4,348 KB
testcase_03 AC 0 ms
4,348 KB
testcase_04 AC 0 ms
4,348 KB
testcase_05 AC 0 ms
4,348 KB
testcase_06 AC 0 ms
4,348 KB
testcase_07 AC 4 ms
8,484 KB
testcase_08 AC 0 ms
4,348 KB
testcase_09 AC 0 ms
4,348 KB
testcase_10 AC 0 ms
4,348 KB
testcase_11 AC 0 ms
4,348 KB
testcase_12 AC 1 ms
4,348 KB
testcase_13 AC 1 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 0 ms
4,348 KB
testcase_16 AC 1 ms
4,348 KB
testcase_17 AC 0 ms
4,348 KB
testcase_18 AC 3 ms
7,120 KB
testcase_19 AC 1 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 0 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘run’:
main.c:8:3: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |   scanf("%d",&n);
      |   ^~~~~~~~~~~~~~
main.c:14:5: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |     scanf("%d",&a);
      |     ^~~~~~~~~~~~~~

ソースコード

diff #

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

#define POS(i,j,k) (((i)*(n+1)+(j))*(n+1)+(k)) 

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

  int cnt[4]={0};
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    cnt[a>=3?3:a]++;
  }
  double *e=(double *)malloc((n+1)*(n+1)*(n+1)*sizeof(double));
  e[POS(0,0,0)]=0.0;

  double p=(double)1/n;
  int j,k;
  for(i=0;i<=cnt[0];i++){
    for(j=0;j<=cnt[1]+cnt[0]-i;j++){
      for(k=(i==0&&j==0);k<=cnt[2]+cnt[1]+cnt[0]-i-j;k++){
	e[POS(i,j,k)]=(1.0+i*p*(i>0?e[POS(i-1,j+1,k)]:0)+j*p*(j>0?e[POS(i,j-1,k+1)]:0)+k*p*(k>0?e[POS(i,j,k-1)]:0))*n/(i+j+k);
      }
    }
  }

  printf("%.6lf\n",e[POS(cnt[0],cnt[1],cnt[2])]);
  free(e);
  return;
}

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