結果

問題 No.309 シャイな人たち (1)
ユーザー fumofumofunifumofumofuni
提出日時 2021-09-15 17:08:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,616 bytes
コンパイル時間 2,293 ms
コンパイル使用メモリ 208,540 KB
実行使用メモリ 8,756 KB
最終ジャッジ日時 2023-09-11 03:22:04
合計ジャッジ時間 14,510 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3,241 ms
8,756 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
} 
int main(){
    ll h,w;cin >> h >> w;
    vector<vector<double>> g(h,vector<double>(w));
    rep(i,h){
        rep(j,w)cin >> g[i][j],g[i][j]/=100;
    }
    vvl s(h,vl(w));
    rep(i,h)rep(j,w)cin >> s[i][j];
    vector<double> dp(1<<w);dp[0]=1;
    double ans=0;
    rep(i,h){
        vector<double> ndp(1<<w);
        vector<double> prob(1<<w,1);
        rep(cit,1<<w){
            rep(j,w){
                if(cit>>j&1)prob[cit]*=g[i][j];
                else prob[cit]*=1.0-g[i][j];
            }
        }
        rep(bit,1<<w){
            if(dp[bit]==0)continue;
            rep(cit,1<<w){
                ll to=0;//実際に手を挙げている
                rep(j,w){
                    ll now=(cit>>j&1? 4-s[i][j]:0);
                    if(bit>>j&1)now++;
                    if(j&&(to>>(j-1)&1))now++;
                    if(j<w-1&&(to>>(j+1)&1))now++;
                    if(now>=4)to|=(1<<j);
                }
                per(j,w){
                    ll now=(cit>>j&1? 4-s[i][j]:0);
                    if(bit>>j&1)now++;
                    if(j&&(to>>(j-1)&1))now++;
                    if(j<w-1&&(to>>(j+1)&1))now++;
                    if(now>=4)to|=(1<<j);
                }
                ndp[to]+=dp[bit]*prob[cit];
                ans+=dp[bit]*prob[cit]*(__builtin_popcount(to));
                /*if(ndp[to]==-1)ndp[to]=(dp[bit]+__builtin_popcount(to))*prob;
                else ndp[to]+=(dp[bit]+__builtin_popcount(to))*prob;*/
            }
        }
        swap(dp,ndp);
    }
    CST(10);
    cout << ans << endl;
}   
0