結果

問題 No.309 シャイな人たち (1)
ユーザー koyumeishikoyumeishi
提出日時 2015-12-02 23:28:35
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,357 bytes
コンパイル時間 714 ms
コンパイル使用メモリ 83,568 KB
実行使用メモリ 4,352 KB
最終ジャッジ日時 2023-10-12 09:11:55
合計ジャッジ時間 29,987 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,948 ms
4,352 KB
testcase_01 AC 3,894 ms
4,348 KB
testcase_02 AC 117 ms
4,348 KB
testcase_03 AC 2,820 ms
4,348 KB
testcase_04 AC 37 ms
4,348 KB
testcase_05 AC 502 ms
4,348 KB
testcase_06 AC 47 ms
4,348 KB
testcase_07 AC 211 ms
4,348 KB
testcase_08 AC 2,916 ms
4,352 KB
testcase_09 AC 3,607 ms
4,348 KB
testcase_10 TLE -
testcase_11 AC 3,611 ms
4,348 KB
testcase_12 AC 2,701 ms
4,348 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

void propagate(vector<int>& y, int& used, int pos){
	if(pos<0 || pos>=y.size()) return;
	if((used>>pos)&1) return;
	y[pos]++;
	if(y[pos]>=4){
		used |= 1<<pos;
		propagate(y, used, pos-1);
		propagate(y, used, pos+1);
	}
}

void propagate_begin(vector<int>& y, int& used, int pos){
	if(pos<0 || pos>=y.size()) return;
	if((used>>pos)&1) return;
	if(y[pos]>=4){
		used |= 1<<pos;
		propagate(y, used, pos-1);
		propagate(y, used, pos+1);
	}
}


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;
}
0