結果

問題 No.76 回数の期待値で練習
ユーザー ocvret_ocvret_
提出日時 2021-02-27 13:52:11
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 967 bytes
コンパイル時間 1,546 ms
コンパイル使用メモリ 170,756 KB
実行使用メモリ 13,880 KB
最終ジャッジ日時 2024-04-10 15:36:15
合計ジャッジ時間 8,052 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
// #include<atcoder/all>
// #include<boost/multiprecision/cpp_int.hpp>

using namespace std;
// using namespace atcoder;
// using bint = boost::multiprecision::cpp_int;
using ll = long long;
using ull = unsigned long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0;i < (ll)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define MOD 1000000007


int main(){
  
  int T;
  cin >> T;
  vector<long double> p(10);
  p[1]=1.0/12;
	p[2]=2.0/12;
	p[3]=3.0/12;
	p[4]=1.0/12;
	p[5]=3.0/12;
	p[6]=2.0/12;
  while(T--){
    int n;
    cin >> n;
    vector<vector<pair<int,long double>>> rv(n+1);
    rep(i,n){
      for(int j = 1;j <= 6;j++){
        int s = i,t = min(i+j,1ll*n);
        rv[t].push_back({s,p[j]});
      }
    }
    vector<long double> back(n+1);
    for(int i = n;i > 0;i--){
      for(auto e : rv[i])back[e.first] += (back[i]+1)*e.second;
    }
    cout << fixed << setprecision(20) << back[0] << "\n";
  }
  

  return 0;
}
0