結果

問題 No.302 サイコロで確率問題 (2)
ユーザー akakimidoriakakimidori
提出日時 2018-04-18 19:10:10
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 4,227 ms / 6,000 ms
コード長 1,295 bytes
コンパイル時間 766 ms
コンパイル使用メモリ 27,732 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-09 11:24:58
合計ジャッジ時間 11,179 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
4,376 KB
testcase_01 AC 671 ms
4,376 KB
testcase_02 AC 4,227 ms
4,376 KB
testcase_03 AC 55 ms
4,384 KB
testcase_04 AC 669 ms
4,380 KB
testcase_05 AC 2,428 ms
4,380 KB
testcase_06 AC 0 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 63 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 108 ms
4,380 KB
testcase_12 AC 0 ms
4,376 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 0 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1,768 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 0 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

//n<=l, r<=6*n
void solveSmall(int n,int l,int r){
  double *now=(double *)malloc(sizeof(double)*(r+1));
  double *next=(double *)malloc(sizeof(double)*(r+1));
  now[0]=1;
  const double p=(double)1/6;
  int i,j,k;
  for(i=1;i<=n;i++){
    for(j=i;j<=MIN(6*i,r);j++) next[j]=0;
    for(j=i-1;j<=MIN(6*(i-1),r);j++){
      for(k=1;k<=6 && k<=r-j;k++){
	next[j+k]+=now[j]*p;
      }
    }
    double *swap=now;
    now=next;
    next=swap;
  }
  double sum=0;
  for(i=l;i<=r;i++) sum+=now[i];
  printf("%.9lf\n",sum);
  free(now);
  free(next);
  return;
}

void solveLarge(int64 n,int64 l,int64 r){
  double e=3.5*n;
  double v=n*(double)35/12;
  double sqv=sqrt(v);
  double ll=(l-0.5-e)/sqv;
  double rr=(r-0.5-e)/sqv;
  double p=(erf(rr/sqrt(2))-erf(ll/sqrt(2)))/2;
  printf("%.9lf\n",p);
  return;
}

void run(void){
  int64 n;
  scanf("%lld",&n);
  int64 l,r;
  scanf("%lld%lld",&l,&r);
  if(l>6*n || r<n){
    printf("0\n");
    return;
  }
  if(n<=16000){
    solveSmall((int)n,(int)MAX(l,n),(int)MIN(6*n,r));
    return;
  }
  solveLarge(n,l,r);
  return;
}

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