結果

問題 No.309 シャイな人たち (1)
ユーザー rickythetarickytheta
提出日時 2015-12-04 20:29:11
言語 C++11
(gcc 11.4.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,383 bytes
コンパイル時間 1,168 ms
コンパイル使用メモリ 151,336 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 14:22:16
合計ジャッジ時間 31,019 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,999 ms
4,352 KB
testcase_01 AC 3,484 ms
4,348 KB
testcase_02 AC 140 ms
4,352 KB
testcase_03 AC 2,541 ms
4,356 KB
testcase_04 AC 33 ms
4,348 KB
testcase_05 AC 448 ms
4,352 KB
testcase_06 AC 55 ms
4,348 KB
testcase_07 AC 238 ms
4,352 KB
testcase_08 AC 2,656 ms
4,352 KB
testcase_09 AC 3,512 ms
4,348 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 3,068 ms
4,348 KB
testcase_13 AC 1 ms
4,352 KB
testcase_14 AC 1 ms
4,352 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

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

int main(){
  // INPUT
  int h,w;
  cin>>h>>w;
  Real p[h][w];
  int s[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];
  }

  Real result = 0.0;
  vector<Real> beforeRaised(1<<w),nowRaised(1<<w);
  beforeRaised[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;
      bool know[w];
      REP(j,w)know[j] = nowmask>>j&1==1;

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

        ll raising = 0;
        ll active[w];
        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){
          ll 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*beforeRaised[beforemask];
        result += __builtin_popcount(raising) * t;
        nowRaised[raising] += t;
        // DEBUG(rate * beforeRaised[beforemask]);
      }
    }
    beforeRaised = nowRaised;
    nowRaised = vector<Real>(1<<w,0);
  }

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