結果

問題 No.212 素数サイコロと合成数サイコロ (2)
ユーザー cureskolcureskol
提出日時 2020-04-11 12:35:53
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 770 bytes
コンパイル時間 1,960 ms
コンパイル使用メモリ 182,928 KB
実行使用メモリ 4,792 KB
最終ジャッジ日時 2023-10-19 01:49:54
合計ジャッジ時間 2,592 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#define int long long
int p[6]={2,3,5,7,11,13},c[6]={4,6,8,9,10,12};
using ld=long double;

signed main(){
  int P,C;cin>>P>>C;
  ld A=pow(6,P+C);
  map<int,int> dp;
  dp[1]=1;
  stack<int> sta;
  while(P--){
    for(auto tmp:dp)sta.push(tmp.first);
    while(sta.size()){
      int tmp=sta.top();sta.pop();
      for(int j=0;j<6;j++){
        dp[tmp*p[j]]+=dp[tmp];
      }
      dp.erase(tmp);
    }
  }

  while(C--){
    for(auto tmp:dp)sta.push(tmp.first);
    while(sta.size()){
      int tmp=sta.top();sta.pop();
      for(int j=0;j<6;j++){
        dp[tmp*c[j]]+=dp[tmp];
      }
      dp.erase(tmp);
    }
  }
  ld sum=0;
  for(auto tmp:dp)sum+=tmp.first*tmp.second;
  cout<<fixed<<setprecision(12)<<sum/A<<endl;
}
0