結果
| 問題 | No.309 シャイな人たち (1) |
| コンテスト | |
| ユーザー |
rickytheta
|
| 提出日時 | 2015-12-04 23:09:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,401 bytes |
| 記録 | |
| コンパイル時間 | 211 ms |
| コンパイル使用メモリ | 27,264 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-14 13:29:36 |
| 合計ジャッジ時間 | 28,614 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 TLE * 2 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
22 | scanf("%d%d",&h,&w);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:26:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
26 | scanf("%d",&tmp);
| ~~~~~^~~~~~~~~~~
main.cpp:30:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d",&s[i][j]);
| ~~~~~^~~~~~~~~~~~~~~
ソースコード
#include <cstdio>
using namespace std;
#define Real double
#define EPS (Real)(1e-12)
#define MAX_H 11
#define MAX_W 11
int h,w;
Real p[MAX_H][MAX_W];
int s[MAX_H][MAX_W];
Real result;
Real raised[MAX_H+1][1<<MAX_W];
bool know[MAX_W];
int raising;
bool raisings[MAX_W];
int active[MAX_W];
int main(){
// INPUT
scanf("%d%d",&h,&w);
int mask_max = 1<<w;
for(int i=0;i<h;++i)for(int j=0;j<w;++j){
int tmp;
scanf("%d",&tmp);
p[i][j] = (double)tmp/100.0;
}
for(int i=0;i<h;++i)for(int j=0;j<w;++j){
scanf("%d",&s[i][j]);
s[i][j] = 4-s[i][j];
}
result = 0.0;
raised[0][0] = 1.0;
for(int i=0;i<h;++i){
// if know then bit 1, else then bit 0
for(int nowmask=0;nowmask<mask_max;++nowmask){
Real rate = 1.0;
for(int j=0;j<w;++j){
if(nowmask>>j & 1 == 1){
rate *= p[i][j];
know[j] = true;
}else{
rate *= (1.0-p[i][j]);
know[j] = false;
}
if(rate<EPS)break;
}
if(rate<EPS)continue;
for(int beforemask=0;beforemask<mask_max;++beforemask){
if(raised[i][beforemask]<EPS)continue;
for(int j=0;j<w;++j){
raisings[j] = false;
active[j] = s[i][j]+(int)(beforemask>>j&1==1);
}
for(int j=0;j<w;++j){
if( active[j]>=4 && know[j] ){
raisings[j] = true;
}
}
// from front & left
for(int j=1;j<w;++j){
if( !raisings[j] && active[j]>=3 && know[j] && raisings[j-1] ){
raisings[j] = true;
}
}
// from front & right
for(int j=w-2;j>=0;--j){
if( !raisings[j] && active[j]>=3 && know[j] && raisings[j+1] ){
raisings[j] = true;
}
}
// from front & left & right
for(int j=1;j<w-1;++j){
if( !raisings[j] && active[j]>=2 && know[j] &&
raisings[j-1] && raisings[j+1] ){
raisings[j] = true;
}
}
raising = 0;
for(int j=0;j<w;++j){
raising <<= 1;
if(raisings[w-1-j])raising += 1;
}
raised[i+1][raising] += rate*raised[i][beforemask];
}
}
}
for(int mask=1;mask<mask_max;++mask){
double cnt = (double)__builtin_popcount(mask);
for(int i=0;i<h;++i){
result += raised[i+1][mask]*cnt;
}
}
printf("%.15f\n",result);
return 0;
}
rickytheta