結果

問題 No.162 8020運動
ユーザー yumakmcyumakmc
提出日時 2016-02-18 05:39:38
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 689 ms / 5,000 ms
コード長 2,101 bytes
コンパイル時間 2,082 ms
コンパイル使用メモリ 191,748 KB
実行使用メモリ 5,756 KB
最終ジャッジ日時 2023-10-22 06:33:04
合計ジャッジ時間 15,421 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,348 KB
testcase_01 AC 314 ms
4,868 KB
testcase_02 AC 500 ms
5,312 KB
testcase_03 AC 685 ms
5,756 KB
testcase_04 AC 685 ms
5,756 KB
testcase_05 AC 685 ms
5,756 KB
testcase_06 AC 685 ms
5,756 KB
testcase_07 AC 686 ms
5,756 KB
testcase_08 AC 689 ms
5,756 KB
testcase_09 AC 14 ms
4,348 KB
testcase_10 AC 500 ms
5,312 KB
testcase_11 AC 314 ms
4,868 KB
testcase_12 AC 128 ms
4,424 KB
testcase_13 AC 686 ms
5,756 KB
testcase_14 AC 22 ms
4,348 KB
testcase_15 AC 22 ms
4,348 KB
testcase_16 AC 165 ms
4,512 KB
testcase_17 AC 54 ms
4,348 KB
testcase_18 AC 645 ms
5,668 KB
testcase_19 AC 460 ms
5,224 KB
testcase_20 AC 536 ms
5,400 KB
testcase_21 AC 535 ms
5,400 KB
testcase_22 AC 502 ms
5,312 KB
testcase_23 AC 538 ms
5,400 KB
testcase_24 AC 500 ms
5,312 KB
testcase_25 AC 573 ms
5,488 KB
testcase_26 AC 14 ms
4,348 KB
testcase_27 AC 354 ms
4,956 KB
testcase_28 AC 650 ms
5,668 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;

map<int, map<vector<int>, ld>>pers;

vector<map<vector<int>, ld>>dp;
int main() {
	int A; cin >> A;
	dp.resize(81 - A);
	ld p[3]; cin >> p[0] >> p[1] >> p[2];
	for (int i = 0; i < 3; ++i){
		p[i] /= 100;
	}
	for (int i = 1; i <= 14; ++i){
		for (int j = 0; j < (1 << i); ++j){
			bitset<14>bs(j);
			ld per = 1;
			for (int k = 0; k < i; ++k){
				if (!bs[k]){
					if (i == 1)per *= p[0];
					else if (k == 0 || k == i - 1)per *= p[1];
					else per *= p[2];
				}
				else{
					if (i == 1)per *= 1-p[0];
					else if (k == 0 || k == i - 1)per *= 1-p[1];
					else per *= 1-p[2];
				}
			}
			int num = 0;
			vector<int>vs;
			for (int k = 0; k < i; ++k){
				if (bs[k]){
					num++;
				}
				else{
					if (num){
						vs.push_back(num);
					}
					num = 0;
				}
			}
			if (num){
				vs.push_back(num);
			}
			sort(vs.begin(), vs.end(), greater<int>());
			pers[i][vs] += per;
		}
	}
	dp[0][vector<int>(1, 14)] = 1;
	for (int i = 0; i < 80 - A; ++i){
		for (auto mp : dp[i]){
			vector<map<vector<int>, ld>>mps;
			for (int j = 0; j < mp.first.size(); ++j){
				mps.push_back(pers[mp.first[j]]);
			}
			int num = 1;
			for (auto j : mps){
				num *= j.size();
			}
			for (int j = 0; j < num; ++j){
				vector<int>selects(mps.size());
				int rest = j;
				for (int k = 0; k < mps.size(); ++k){
					selects[k] = rest%mps[k].size();
					rest /= mps[k].size();
				}
				vector<int>ans;
				ld aper = 1;
				for (int k = 0; k < mps.size(); ++k){
					auto it = mps[k].begin();
					while (selects[k]){
						it++;
						selects[k]--;
					}
					ans.insert(ans.end(), it->first.begin(), it->first.end());
					aper *= it->second;
				}
				dp[i + 1][ans] += aper*mp.second;
			}
		}
	}
	ld finans = 0;
	for (auto j : dp[80 - A]){
		int teeth = 0;
		for (int k = 0; k < j.first.size(); ++k){
			teeth += j.first[k];
		}
		finans += j.second*teeth*2;
	}
	cout <<fixed<<setprecision(22)<< finans << endl;
	return 0;
}
0