結果

問題 No.309 シャイな人たち (1)
ユーザー 👑 kmjpkmjp
提出日時 2015-12-05 00:24:25
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 3,705 ms / 4,000 ms
コード長 1,536 bytes
コンパイル時間 2,129 ms
コンパイル使用メモリ 146,520 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-25 02:32:57
合計ジャッジ時間 29,678 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,828 ms
4,380 KB
testcase_01 AC 3,648 ms
4,380 KB
testcase_02 AC 140 ms
4,380 KB
testcase_03 AC 2,651 ms
4,380 KB
testcase_04 AC 34 ms
4,380 KB
testcase_05 AC 466 ms
4,376 KB
testcase_06 AC 133 ms
4,376 KB
testcase_07 AC 234 ms
4,380 KB
testcase_08 AC 2,720 ms
4,376 KB
testcase_09 AC 3,368 ms
4,376 KB
testcase_10 AC 3,705 ms
4,380 KB
testcase_11 AC 3,337 ms
4,380 KB
testcase_12 AC 2,536 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<to;x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int H,W;
double P[101][101];
int S[101][101];

double dp[13][1<<11];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>H>>W;
	FOR(y,H) FOR(x,W) cin>>r, P[y][x] = r/100.0;
	FOR(y,H) FOR(x,W) cin>>S[y][x];
	
	double ret=0;
	dp[0][0]=1;
	FOR(y,H) {
		for(int cur=0;cur<1<<W;cur++) {
			double pat=1;
			int hand=0;
			FOR(x,W) {
				if(cur&(1<<x)) {
					pat *= P[y][x];
					if(S[y][x]==0) hand |= 1<<(x+1);
				}
				else pat *= 1-P[y][x];
			}
			for(int up=0;up<1<<W;up++) if(dp[y][up]>1e-12) {
				int hand2=hand;
				FOR(j,2) FOR(i,W) {
					x=(j)?i:(W-1-i);
					if(cur&(1<<x)) {
						int p=4-S[y][x];
						if(hand2&(1<<x)) p++;
						if(hand2&(1<<(x+2))) p++;
						if(up&(1<<x)) p++;
						if(p>=4) hand2 |= 1<<(x+1);
					}
				}
				
				hand2 >>=1;
				ret += pat*dp[y][up]*__builtin_popcount(hand2);
				dp[y+1][hand2] += pat*dp[y][up];
			}
		}
	}
	
	_P("%.12lf\n",ret);
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}
0