結果

問題 No.309 シャイな人たち (1)
ユーザー piyoko_212piyoko_212
提出日時 2015-12-25 23:24:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,445 bytes
コンパイル時間 405 ms
コンパイル使用メモリ 44,924 KB
実行使用メモリ 18,380 KB
最終ジャッジ日時 2023-10-19 03:51:20
合計ジャッジ時間 5,417 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 348 ms
18,372 KB
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 1 ms
4,348 KB
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         int a,b;scanf("%d%d",&a,&b);
      |                 ~~~~~^~~~~~~~~~~~~~
main.cpp:16:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 |         for(int i=0;i<a;i++)for(int j=0;j<b;j++)scanf("%d",&p[i][j]);
      |                                                 ~~~~~^~~~~~~~~~~~~~~
main.cpp:17:54: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   17 |         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];
int si[1<<22];
int mask[1<<11];
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++){
		for(int j=0;j<b;j++){
			if(!(i&(1<<j))){
				mask[i]+=(1<<(j*2))+(1<<(j*2+1));
			}
		}
	}
	for(int i=0;i<(1<<(b*2));i++){
		for(int j=0;j<b;j++){
			st[j]=3-(i>>(j*2))%4;
		}
		for(int j=0;j<b-1;j++){
			if(st[j]>=3)st[j+1]++;
		}
		for(int j=b-1;j>0;j--){
			if(st[j]>=3)st[j-1]++;
		}
		int to=0;
		for(int j=0;j<b;j++)if(st[j]>=3)to+=(1<<j);
		si[i]=to;
	}
	dp[0][0]=1;
	for(int i=0;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]/100;
				}else{
					th=th*(100-p[i][k])/100;
				}
			}
			pr[j]=th;
		}
		for(int k=0;k<(1<<b);k++){
			if(dp[i][k]<EPS)continue;
			int req=0;
			for(int l=b-1;l>=0;l--){
				req=q[i][l];
				if(q[i][l]&&(k&(1<<l)))req--;
				if(req==4)req--;
				req*=4;
			}
			for(int l=0;l<(1<<b);l++){
				if(pr[l]<EPS)continue;
				
				dp[i+1][si[req|mask[l]]]+=pr[l]*dp[i][k];
			}
		}
	}
	double ret=0;
	for(int i=1;i<=a;i++){
		for(int j=0;j<(1<<b);j++){
			ret+=dp[i][j]*(__builtin_popcount(j));
		}
	}
	printf("%.12f\n",ret);
}
0