結果
問題 | No.309 シャイな人たち (1) |
ユーザー | kimiyuki |
提出日時 | 2015-12-03 00:53:35 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2,475 ms / 4,000 ms |
コード長 | 2,277 bytes |
コンパイル時間 | 651 ms |
コンパイル使用メモリ | 73,124 KB |
実行使用メモリ | 4,356 KB |
最終ジャッジ日時 | 2023-10-12 09:17:02 |
合計ジャッジ時間 | 29,267 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2,475 ms
4,352 KB |
testcase_01 | AC | 1,863 ms
4,352 KB |
testcase_02 | AC | 2,293 ms
4,352 KB |
testcase_03 | AC | 1,949 ms
4,352 KB |
testcase_04 | AC | 24 ms
4,348 KB |
testcase_05 | AC | 392 ms
4,348 KB |
testcase_06 | AC | 2,410 ms
4,348 KB |
testcase_07 | AC | 2,438 ms
4,352 KB |
testcase_08 | AC | 2,118 ms
4,348 KB |
testcase_09 | AC | 2,148 ms
4,352 KB |
testcase_10 | AC | 2,135 ms
4,356 KB |
testcase_11 | AC | 2,203 ms
4,352 KB |
testcase_12 | AC | 2,123 ms
4,348 KB |
testcase_13 | AC | 2 ms
4,352 KB |
testcase_14 | AC | 1 ms
4,348 KB |
testcase_15 | AC | 548 ms
4,352 KB |
ソースコード
#include <iostream> #include <cstdio> #include <array> #include <vector> #include <algorithm> #define repeat(i,n) for (int i = 0; (i) < (n); ++(i)) #define repeat_from(i,m,n) for (int i = (m); (i) < (n); ++(i)) #define repeat_reverse(i,n) for (int i = (n)-1; (i) >= 0; --(i)) using namespace std; double por(double p, double q) { // probability or return 1 - (1-p)*(1-q); } inline bool at(int s, int i) { return s & (1 << i); } int main() { int h, w; cin >> h >> w; vector<vector<double> > p(h, vector<double>(w)); repeat (y,h) repeat (x,w) { cin >> p[y][x]; p[y][x] /= 100; } vector<vector<int > > s(h, vector<int >(w)); repeat (y,h) repeat (x,w) cin >> s[y][x]; vector<vector<double> > dp(h+1, vector<double>(1<<w)); // dp[y][hand] = probability dp[0][0] = 1; repeat (y,h) { repeat (knowledge,1<<w) { double q = 1; repeat (x,w) q *= at(knowledge,x) ? p[y][x] : 1 - p[y][x]; repeat (phand,1<<w) { int hand = 0; repeat (x,w) { if (s[y][x] == 0 and at(knowledge,x)) hand |= (1<<x); if (s[y][x] == 1 and at(knowledge,x) and at(phand,x)) hand |= (1<<x); } repeat_from (x,1,w) { if (s[y][x] == 1 and at(knowledge,x) and at(hand,x-1)) hand |= (1<<x); if (s[y][x] == 2 and at(knowledge,x) and at(hand,x-1) and at(phand,x)) hand |= (1<<x); } repeat_reverse (x,w-1) { if (s[y][x] == 1 and at(knowledge,x) and at(hand,x+1)) hand |= (1<<x); if (s[y][x] == 2 and at(knowledge,x) and at(hand,x+1) and at(phand,x)) hand |= (1<<x); } repeat_from (x,1,w-1) { if (s[y][x] == 2 and at(knowledge,x) and at(hand,x-1) and at(hand,x+1)) hand |= (1<<x); if (s[y][x] == 3 and at(knowledge,x) and at(hand,x-1) and at(hand,x+1) and at(phand,x)) hand |= (1<<x); } dp[y+1][hand] += q * dp[y][phand]; } } } double result = 0; repeat (y,h) repeat (row,1<<w) { result += __builtin_popcount(row) * dp[y+1][row]; } printf("%.12lf\n", result); return 0; }