結果

問題 No.309 シャイな人たち (1)
ユーザー chocoruskchocorusk
提出日時 2019-12-29 04:03:28
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 3,355 ms / 4,000 ms
コード長 2,109 bytes
コンパイル時間 1,155 ms
コンパイル使用メモリ 113,084 KB
実行使用メモリ 36,900 KB
最終ジャッジ日時 2023-08-20 13:39:02
合計ジャッジ時間 27,504 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,807 ms
36,784 KB
testcase_01 AC 3,254 ms
36,788 KB
testcase_02 AC 419 ms
36,812 KB
testcase_03 AC 2,461 ms
36,900 KB
testcase_04 AC 39 ms
20,672 KB
testcase_05 AC 465 ms
25,188 KB
testcase_06 AC 415 ms
36,792 KB
testcase_07 AC 488 ms
36,752 KB
testcase_08 AC 2,520 ms
36,804 KB
testcase_09 AC 3,033 ms
36,804 KB
testcase_10 AC 3,355 ms
36,880 KB
testcase_11 AC 2,987 ms
36,808 KB
testcase_12 AC 2,342 ms
36,840 KB
testcase_13 AC 6 ms
21,084 KB
testcase_14 AC 7 ms
21,448 KB
testcase_15 AC 98 ms
26,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	int r, c; cin>>r>>c;
	double p[11][11]; int s[11][11]={};
	for(int i=0; i<r; i++) for(int j=0; j<c; j++) cin>>p[i][j];
	for(int i=0; i<r; i++) for(int j=0; j<c; j++) cin>>s[i][j];
	double dp[12][1<<11]={};
	dp[0][0]=1;
	double ans=0;
	double q[11][1<<11];
	for(int i=0; i<r; i++){
		for(int k=0; k<(1<<c); k++){
			q[i][k]=1;
			for(int l=0; l<c; l++){
				if(k&(1<<l)){
					q[i][k]*=p[i][l]/100;
				}else{
					q[i][k]*=(100-p[i][l])/100;
				}
			}
		}
	}
	int nuo[1<<22]={};
	int nue[1<<22];
	for(int i=0; i<(1<<(2*c)); i++){
		int cnt[11];
		bool used[11]={};
		int que[30];
		int t=0, u=0;
		for(int j=0; j<c; j++){
			cnt[j]=((i>>(2*j))&3);
			if(cnt[j]==0){
				que[u]=j; u++;
				used[j]=1;
				nuo[i]^=(1<<j);
			}else if(cnt[j]==3) used[j]=1;
		}
		while(t<u){
			int x=que[t]; t++;
			if(x>0 && !used[x-1]){
				cnt[x-1]--;
				if(cnt[x-1]==0){
					que[u]=x-1; u++;
					used[x-1]=1;
					nuo[i]^=(1<<(x-1));
				}
			}
			if(x<c-1 && !used[x+1]){
				cnt[x+1]--;
				if(cnt[x+1]==0){
					que[u]=x+1; u++;
					used[x+1]=1;
					nuo[i]^=(1<<(x+1));
				}
			}
		}
		nue[i]=popcount(nuo[i]);
	}
	for(int i=0; i<r; i++){
		for(int j=0; j<(1<<c); j++){
			if(dp[i][j]==0) continue;
			for(int k=0; k<(1<<c); k++){
				int x=0;
				for(int l=0; l<c; l++){
					if(k&(1<<l)){
						if(j&(1<<l)) x^=(max(s[i][l]-1, 0)<<(2*l));
						else x^=(min(s[i][l], 3)<<(2*l));
					}else{
						x^=(3<<(2*l));
					}
				}
				double myon=q[i][k]*dp[i][j];
				dp[i+1][nuo[x]]+=myon;
				ans+=myon*nue[x];
			}
		}
	}
	printf("%.9lf\n", ans);
	return 0;
}
0