結果

問題 No.309 シャイな人たち (1)
ユーザー koyumeishikoyumeishi
提出日時 2015-12-02 23:45:06
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 3,528 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 86,428 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-12 09:13:09
合計ジャッジ時間 13,379 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;

template<class T>
ostream& operator << (ostream& os, vector<T> vec){
	for(int i=0; i<vec.size(); i++){
		os << vec[i] << " ";
	}
	return os;
}
#include <bitset>


int main_(){
	int r,c;
	cin >> r >> c;
	vector<vector<int>> p(r, vector<int>(c));
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >> p[i][j];
		}
	}
	vector<vector<int>> s(r, vector<int>(c));
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >> s[i][j];
		}
	}

	vector<double> Prob(1<<c, 0);
	Prob[0] = 1.0;
	vector<double> dp(1<<c, 0);
	for(int i=0; i<r; i++){
		vector<double> dp_(1<<c, 0);
		vector<double> next_Prob(1<<c, 0);
		double hoge = 0;

		for(int w=0; w<(1<<c); w++){
			double tmp_p = 1.0;
			vector<int> y(c, 0);

			for(int j=0; j<c; j++){
				tmp_p *= (((w>>j)&1)?p[i][j]:100-p[i][j])/100.0;
				if((w>>j)&1){
					y[j] = 4-s[i][j];
				}
			}

			if(tmp_p < 1e-12) continue;

			for(int v=0; v<(1<<c); v++){
				if(Prob[v] < 1e-12) continue;

				auto z=y;
				int used = 0;
				for(int j=0; j<c; j++){
					z[j] += (v>>j)&1;
				}

				for(int j=0; j<c; j++){
					if(z[j]>=4 && ((used>>j)&1)!=1){
						used |= 1<<j;
						if(j-1>=0) z[j-1]++;
						if(j+1< c) z[j+1]++;
					}
				}

				for(int j=c-1; j>=0; j--){
					if(z[j]>=4 && ((used>>j)&1)!=1){
						used |= 1<<j;
						if(j-1>=0) z[j-1]++;
						if(j+1< c) z[j+1]++;
					}
				}


				int next = 0;
				int cnt = 0;
				for(int j=0; j<c; j++){
					next |= (z[j]>=4)<<j;
					cnt += (z[j]>=4);
				}
				dp_[next] += (dp[v] + cnt * Prob[v]) * tmp_p;
				next_Prob[next] += Prob[v] * tmp_p;
			}
		}

		swap(dp, dp_);
		swap(Prob, next_Prob);
	}

	double ans = 0;
	for(int i=0; i<(1<<c); i++){
		ans += dp[i];
	}
	printf("%.18f\n", ans);
	return 0;
}


int main(){
	int r,c;
	cin >> r >> c;
	vector<vector<int>> p(r, vector<int>(c));
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >> p[i][j];
		}
	}
	vector<vector<int>> s(r, vector<int>(c));
	for(int i=0; i<r; i++){
		for(int j=0; j<c; j++){
			cin >> s[i][j];
		}
	}

	vector<double> Prob(1<<c, 0);
	vector<double> Prob_(1<<c, 0);
	Prob[0] = 1.0;

	vector<double> dp(1<<c, 0);
	vector<double> dp_(1<<c, 0);

	for(int i=0; i<r; i++){


		for(int v=0; v<(1<<c); v++){
			if(Prob[v] < 1e-10){
				dp[v] = 0;
				Prob[v] = 0;
				continue;
			}

			vector<int> y(c, 0);
			for(int j=0; j<c; j++){
				y[j] += (v>>j)&1;
			}
			for(int w=0; w<(1<<c); w++){
				double tmp_p = 1.0;
				auto z=y;
				for(int j=0; j<c; j++){
					tmp_p *= (((w>>j)&1)?p[i][j]:100-p[i][j])/100.0;
					if((w>>j)&1){
						z[j] += 4-s[i][j];
					}
				}
				if(tmp_p < 1e-10) continue;

				//propagate
				int used = 0;
				for(int j=0; j<c; j++){
					if(z[j]>=4 && ((used>>j)&1)!=1){
						used |= 1<<j;
						if(j-1>=0) z[j-1]++;
						if(j+1< c) z[j+1]++;
					}
				}
				for(int j=c-1; j>=0; j--){
					if(z[j]>=4 && ((used>>j)&1)!=1){
						used |= 1<<j;
						if(j-1>=0) z[j-1]++;
						if(j+1< c) z[j+1]++;
					}
				}

				int next = 0;
				int cnt = 0;
				for(int j=0; j<c; j++){
					next |= (z[j]>=4)<<j;
					cnt += (z[j]>=4);
				}
				dp_[next] += (dp[v] + cnt * Prob[v]) * tmp_p;
				Prob_[next] += Prob[v] * tmp_p;
			}
			
			dp[v] = 0;
			Prob[v] = 0;
		}

		swap(dp, dp_);
		swap(Prob, Prob_);
	}

	double ans = 0;
	for(int i=0; i<(1<<c); i++){
		ans += dp[i];
	}
	printf("%.18f\n", ans);
	return 0;
}
0