結果

問題 No.309 シャイな人たち (1)
ユーザー rickythetarickytheta
提出日時 2015-12-04 21:25:01
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 2,016 bytes
コンパイル時間 890 ms
コンパイル使用メモリ 55,812 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2023-10-12 14:30:32
合計ジャッジ時間 24,062 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2,107 ms
8,704 KB
testcase_01 AC 3,608 ms
4,348 KB
testcase_02 AC 107 ms
4,348 KB
testcase_03 AC 2,651 ms
4,352 KB
testcase_04 AC 34 ms
4,348 KB
testcase_05 AC 462 ms
4,348 KB
testcase_06 AC 42 ms
4,352 KB
testcase_07 AC 207 ms
4,348 KB
testcase_08 AC 2,715 ms
4,352 KB
testcase_09 AC 3,538 ms
4,352 KB
testcase_10 TLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// #include <bits/stdc++.h>
#include <iostream>

using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=1;i<n;++i)

#define Real double
#define EPS (Real)(1e-12)

int h,w;
#define MAX_H 11
#define MAX_W 11
Real p[MAX_H][MAX_W];
int s[MAX_H][MAX_W];
Real result;
Real raised[2][1<<MAX_W];
int bef,nxt;
bool know[MAX_W];
int raising;
int active[MAX_W];

int main(){
  // INPUT
  cin>>h>>w;
  REP(i,h)REP(j,w){
    cin>>p[i][j];
    p[i][j]/=100.0;
  }
  REP(i,h)REP(j,w){
    cin>>s[i][j];
    s[i][j] = 4-s[i][j];
  }
  result = 0.0;
  bef = 0;
  nxt = 1;
  raised[bef][0] = 1.0;
  REP(i,h){
    // if know then bit 1, else then bit 0
    REP(nowmask,1<<w){
      Real rate = 1.0;
      REP(j,w){
        if(nowmask>>j & 1 == 1) rate *= p[i][j];
        else                    rate *= (1.0-p[i][j]);
      }
      if(rate<EPS)continue;
      REP(j,w)know[j] = nowmask>>j&1==1;

      REP(beforemask,1<<w){
        if(raised[bef][beforemask]<EPS)continue;

        raising = 0;
        REP(j,w){
          active[j] = s[i][j]+(int)(beforemask>>j&1==1);
        }
        REP(j,w){
          if( active[j]>=4 && know[j] )
            raising |= (1<<j);
        }
        // from front & left
        REPR(j,w){
          if( active[j]>=3 && know[j] && raising>>(j-1)&1==1 )
            raising |= (1<<j);
        }
        // from front & right
        REPR(_j,w){
          int j = w-1-_j;
          if( active[j]>=3 && know[j] && raising>>(j+1)&1==1 )
            raising |= (1<<j);
        }
        // from front & left & right
        REPR(j,w-1){
          if( active[j]>=2 && know[j] &&
            raising>>(j-1)&1==1 && raising>>(j+1)&1==1 )
            raising |= (1<<j);
        }

        Real t = rate*raised[bef][beforemask];
        result += __builtin_popcount(raising) * t;
        raised[nxt][raising] += t;
      }
    }
    bef = 1-bef;
    nxt = 1-nxt;
    REP(j,1<<w)raised[nxt][j]=0.0;
  }

  cout.precision(15);
  cout << fixed << result << endl;
  return 0;
}
0