結果

問題 No.309 シャイな人たち (1)
ユーザー piyoko_212piyoko_212
提出日時 2015-12-25 21:05:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,040 bytes
コンパイル時間 558 ms
コンパイル使用メモリ 50,560 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-19 03:49:16
合計ジャッジ時間 25,286 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
4,348 KB
testcase_14 WA -
testcase_15 AC 3 ms
4,348 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:13:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   13 |         int a,b;scanf("%d%d",&a,&b);
      |                 ~~~~~^~~~~~~~~~~~~~
main.cpp:14:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
      |                                                 ~~~~~^~~~~~~~~~~~~~~
main.cpp:15:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&q[i][j]);
      |                                                 ~~~~~^~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
int p[20][20];
int q[20][20];
double dp[13][1<<11];
int st[20];
double pr[1<<11];
int v[20];
double EPS=1e-9;
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
	for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&q[i][j]);
	for(int i=0;i<(1<<b);i++){
		double th=1;
		for(int j=0;j<b;j++){
			if(i&(1<<j)){
				th=th*p[0][j]/100;
			}else{
				th=th*(100-p[0][j])/100;
			}
		}
		for(int j=0;j<b;j++)st[j]=v[j]=0;
		for(int j=0;j<b;j++){
			if(i&(1<<j))st[j]+=4-q[0][j];
		}
		queue<int>Q;
		for(int j=0;j<b;j++){
			if(st[j]>=4){
				Q.push(j);v[j]=1;
			}
		}
		while(Q.size()){
			int at=Q.front();Q.pop();
			if(at){
				st[at-1]++;
				if(st[at-1]==4){Q.push(at-1);v[at-1]=1;}
			}
			if(at<b-1){
				st[at+1]++;
				if(st[at+1]==4){Q.push(at+1);v[at+1]=1;}
			}
		}
		int to=0;
		for(int j=0;j<b;j++)if(v[j])to+=(1<<j);
		dp[1][to]+=th;
	}
	for(int i=1;i<a;i++){
		for(int j=0;j<(1<<b);j++){
			double th=1;
			for(int k=0;k<b;k++){
				if(j&(1<<k)){
					th=th*p[i][k]/50;
				}else{
					th=th*(50-p[i][k])/50;
				}
			}
			pr[j]=th;
		}
		for(int k=0;k<(1<<b);k++){
			if(dp[i][k]<EPS)continue;
			for(int l=0;l<(1<<b);l++){
				if(pr[l]<EPS)continue;
				for(int j=0;j<b;j++)st[j]=v[j]=0;
				for(int j=0;j<b;j++){
					if(l&(1<<j))st[j]+=4-q[i][j];
					if(k&(1<<j))st[j]++;
				}
				queue<int>Q;
				for(int j=0;j<b;j++){
					if(st[j]>=4){
						Q.push(j);v[j]=1;
					}
				}
				while(Q.size()){
					int at=Q.front();Q.pop();
					if(at){
						st[at-1]++;
						if(st[at-1]==4){Q.push(at-1);v[at-1]=1;}
					}
					if(at<b-1){
						st[at+1]++;
						if(st[at+1]==4){Q.push(at+1);v[at+1]=1;}
					}
				}
				int to=0;
				for(int j=0;j<b;j++)if(v[j])to+=(1<<j);
				dp[i+1][to]+=pr[l]*dp[i][k];
			}
		}
	}
	double ret=0;
	for(int i=1;i<=a;i++){
		for(int j=0;j<(1<<b);j++){
		//	printf("%d %d: %f\n",i,j,dp[i][j]);
			ret+=dp[i][j]*(__builtin_popcount(j));
		}
	}
	printf("%.12f\n",ret);
}
0