結果

問題 No.302 サイコロで確率問題 (2)
ユーザー fumofumofunifumofumofuni
提出日時 2021-09-10 21:07:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,762 ms / 6,000 ms
コード長 2,148 bytes
コンパイル時間 3,344 ms
コンパイル使用メモリ 201,376 KB
実行使用メモリ 5,432 KB
最終ジャッジ日時 2023-09-02 15:17:31
合計ジャッジ時間 14,243 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 10 ms
4,380 KB
testcase_01 AC 331 ms
4,376 KB
testcase_02 AC 2,762 ms
5,432 KB
testcase_03 AC 19 ms
4,376 KB
testcase_04 AC 329 ms
4,380 KB
testcase_05 AC 1,443 ms
4,664 KB
testcase_06 AC 96 ms
4,380 KB
testcase_07 AC 96 ms
4,376 KB
testcase_08 AC 22 ms
4,376 KB
testcase_09 AC 101 ms
4,380 KB
testcase_10 AC 280 ms
4,384 KB
testcase_11 AC 30 ms
4,384 KB
testcase_12 AC 2,165 ms
5,132 KB
testcase_13 AC 286 ms
4,380 KB
testcase_14 AC 1,269 ms
4,588 KB
testcase_15 AC 276 ms
4,380 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 1,011 ms
4,644 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=2e9+1;
const ll INF=4e18;
const ll dy[8]={-1,0,1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}
using ld=double;
ld f(ld x){//標準正規分布のxの値
  return expl(-x*x/2)/sqrtl(acosl(-1.0)*2);
}

ld simpson(ld x0,ld x_max){
    ll n=1000000;
    ld delta = (x_max - x0)/n;
    ld a;
    a = f(x0);
    a += f(x0 + delta * n);
    int i;
    for(i=1; i<n; i+=2){
        a +=  f(x0 + delta * i) * 4;
    }
    for(i=2; i<n; i+=2){
        a +=  f(x0 + delta * i) * 2;
    }
    return a*delta/3.0;
}
ld calc(ld m,ld s,ld a,ld b){//平均m,標準偏差sの確率変数Xがa<X<bとなる確率
  a=max((a-m)/s,(ld)-10.0);
  b=min((b-m)/s,(ld)10.0);
  //ld width=(b-a)/10000000;
  //cout << width << endl;
  return simpson(a,b);
  /*ld ans=0;
  for(ld x=a;x<=b;x+=width)ans+=width*phi(x+width/2);
  return ans;*/
}
int main(){
  ll n,l,r;cin >> n >> l >> r;
  chmax(l,n);chmin(r,n*6);
  CST(10);
  if(n>20000){
    ld m=3.5*n;
    ld s=35.0*n;s/=12;s=sqrtl(s);
    cout << calc(m,s,l,r) << endl;
  }
  else{
    vector<ld> dp={1};
    rep(i,n){
      vector<ld> ndp((i+1)*6+2);
      rep(j,dp.size()){
        if(dp[j]<1e-10)continue;
        rep(k,6)ndp[j+k+1]+=dp[j]/6;
      }
      swap(dp,ndp);
    }
    ld ans=0;
    for(ll i=l;i<=r;i++)ans+=dp[i];
    cout << ans << endl;
  }
}
0