結果

問題 No.58 イカサマなサイコロ
ユーザー beetbeet
提出日時 2018-11-12 17:42:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 1,005 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 201,100 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 02:35:49
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct Precision{
  Precision(){
    cout<<fixed<<setprecision(12);
  }
}precision_beet;

//INSERT ABOVE HERE
signed main(){
  int n,k;
  cin>>n>>k;
  const int MAX = 100;
  vector<double> dp1(MAX,0),dp2(MAX,0);
  dp1[0]=dp2[0]=1;
  for(int i=0;i<n;i++){
    vector<double> nx1(MAX,0),nx2(MAX,0);
    for(int j=0;j+6<MAX;j++){
      if(i<k){
        for(int a=1;a<=6;a++){
          nx1[j+a]+=dp1[j]/6.0;
          nx2[j+(a<4?a+3:a)]+=dp2[j]/6.0;        
        }
      }else{
        for(int a=1;a<=6;a++){
          nx1[j+a]+=dp1[j]/6.0;
          nx2[j+a]+=dp2[j]/6.0;        
        }
      }
    }
    swap(dp1,nx1);
    swap(dp2,nx2);
  }
  
  double ans=0;
  for(int i=0;i<MAX;i++)
    for(int j=i+1;j<MAX;j++)
      ans+=dp1[i]*dp2[j];
  cout<<ans<<endl;
  return 0;
}
0