結果
問題 | No.309 シャイな人たち (1) |
ユーザー |
|
提出日時 | 2023-05-16 03:28:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,855 ms / 4,000 ms |
コード長 | 2,417 bytes |
コンパイル時間 | 1,920 ms |
コンパイル使用メモリ | 179,736 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-14 07:03:08 |
合計ジャッジ時間 | 20,527 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 13 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ios::sync_with_stdio(false);cin.tie(0);int h, w;cin >> h >> w;vector<vector<double>> P(h, vector<double>(w));vector<vector<int>> S(h, vector<int>(w));for(int y = 0; y < h; y++){for(int x = 0; x < w; x++){cin >> P[y][x];P[y][x] /= 100;}}for(int y = 0; y < h; y++){for(int x = 0; x < w; x++){cin >> S[y][x];}}vector<double> pre(1 << w), dp(1 << w);pre[0] = 1;queue<int> que;double ans = 0;for(int y = 0; y < h; y++){//S1:現在の列が知っているか否か//S0:前の列が手を上げたか否かauto f = [&](int S0, int S1, int visited, int x){int tmp = (S0 >> x & 1) + (visited >> x + 1 & 1) + (x ? visited >> x - 1 & 1 : 0);if(S1 >> x & 1) tmp += 4 - S[y][x];return (tmp >= 4);};for(int S1 = 0; S1 < (1 << w); S1++){double prob = 1;for(int x = 0; x < w; x++){if(S1 >> x & 1) prob *= P[y][x];else prob *= 1 - P[y][x];}for(int S0 = 0; S0 < (1 << w); S0++){if(pre[S0] == 0) continue;int visited = 0;for(int x = 0; x < w; x++){if((S0 >> x & 1) + (S1 >> x & 1 ? 4 - S[y][x] : 0) >= 4){visited |= 1 << x;que.emplace(x);}}while(!que.empty()){int x = que.front();que.pop();if(x + 1 < w && (~visited >> x + 1 & 1) && f(S0, S1, visited, x + 1)){visited |= 1 << x + 1;que.emplace(x + 1);}if(x >= 1 && (~visited >> x - 1 & 1) && f(S0, S1, visited, x - 1)){visited |= 1 << x - 1;que.emplace(x - 1);}}dp[visited] += prob * pre[S0];}}for(int bit = 0; bit < (1 << w); bit++){ans += __builtin_popcount(bit) * dp[bit];pre[bit] = dp[bit];dp[bit] = 0;}}cout << fixed << setprecision(15) << ans << '\n';}