結果

問題 No.108 トリプルカードコンプ
ユーザー akakimidoriakakimidori
提出日時 2017-06-03 23:49:20
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 9 ms / 5,000 ms
コード長 798 bytes
コンパイル時間 158 ms
コンパイル使用メモリ 23,480 KB
実行使用メモリ 5,552 KB
最終ジャッジ日時 2023-10-22 03:09:52
合計ジャッジ時間 1,316 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

double calc(double *e,int n,int i,int j,int k){
  if(i==0 && j==0 && k==0) return 0.0;
  if(e[POS(i,j,k)]>=1.0) return e[POS(i,j,k)];

  double t=1.0;
  if(i>0) t+=(double)i/n*calc(e,n,i-1,j+1,k);

  if(j>0) t+=(double)j/n*calc(e,n,i,j-1,k+1);

  if(k>0) t+=(double)k/n*calc(e,n,i,j,k-1);

  t/=1-(double)(n-i-j-k)/n;

  e[POS(i,j,k)]=t;
  return t;
}

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 *)calloc((n+1)*(n+1)*(n+1),sizeof(double));
  calc(e,n,cnt[0],cnt[1],cnt[2]);

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

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