結果
| 問題 |
No.162 8020運動
|
| コンテスト | |
| ユーザー |
tottoripaper
|
| 提出日時 | 2015-03-28 17:12:07 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 878 ms / 5,000 ms |
| コード長 | 1,305 bytes |
| コンパイル時間 | 303 ms |
| コンパイル使用メモリ | 39,680 KB |
| 実行使用メモリ | 82,176 KB |
| 最終ジャッジ日時 | 2024-06-29 01:32:01 |
| 合計ジャッジ時間 | 24,881 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:34:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
34 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
main.cpp:37:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
37 | scanf("%lf %lf %lf", P, P+1, P+2);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
// Wrongri-La Shower
#include <cstdio>
#include <vector>
typedef std::pair<int,double> Pair;
double P[3]; // 虫歯に「なる」確率
std::vector<Pair> ns[1<<14];
double dp[21][1<<14];
double probability(int prev, int next){
double res = 1.0;
for(int i=0;i<14;i++){
if(!(prev >> i & 1)){continue;}
double p;
if(i == 0){
p = P[prev >> 1 & 1];
}else if(i == 13){
p = P[prev >> 12 & 1];
}else{
p = P[(prev >> i-1 & 1) + (prev >> i+1 & 1)];
}
res *= next >> i & 1 ? 1.0-p : p;
}
return res;
}
int main(){
int N;
scanf("%d", &N);
N = 80-N;
scanf("%lf %lf %lf", P, P+1, P+2);
for(int i=0;i<3;i++){P[i] /= 100;}
for(int i=0;i<1<<14;i++){
for(int j=0;j<1<<14;j++){
if((i & j) != j){continue;}
ns[i].push_back(std::make_pair(j, probability(i, j)));
}
}
dp[0][(1<<14)-1] = 1.0;
for(int i=0;i<N;i++){
for(int j=0;j<1<<14;j++){
for(const auto& p : ns[j]){
dp[i+1][p.first] += dp[i][j] * p.second;
}
}
}
double res = 0.0;
for(int i=0;i<1<<14;i++){
res += dp[N][i] * __builtin_popcount(i);
}
printf("%.12f\n", res * 2);
}
tottoripaper