結果
| 問題 | No.309 シャイな人たち (1) |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-12-02 20:10:39 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,213 bytes |
| 記録 | |
| コンパイル時間 | 734 ms |
| コンパイル使用メモリ | 73,424 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-09-14 08:01:18 |
| 合計ジャッジ時間 | 1,401 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 WA * 12 |
ソースコード
#include <iostream>
#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);
}
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, vector<double>(w));
repeat (y,h) {
array<vector<double>,3> q; fill(q.begin(), q.end(), vector<double>(w));
repeat (x,w) {
if (s[y][x] == 0) {
q[0][x] = p[y][x];
}
if (s[y][x] == 1 and y-1 >= 0) {
q[0][x] = p[y][x] * dp[y-1][x];;
}
}
vector<double> l(w);
repeat_from (x,1,w) {
if (s[y][x] == 1) {
l[x] = por(l[x], p[y][x] * por(l[x-1], q[0][x-1]));
}
if (s[y][x] == 2 and y-1 >= 0) {
l[x] = p[y][x] * dp[y-1][x] * por(l[x-1], q[0][x-1]);
}
}
vector<double> r(w);
repeat_reverse (x,w-1) {
if (s[y][x] == 1) {
r[x] = por(r[x], p[y][x] * por(r[x+1], q[0][x+1]));
}
if (s[y][x] == 2 and y-1 >= 0) {
r[x] = p[y][x] * dp[y-1][x] * por(r[x+1], q[0][x+1]);
}
}
repeat (x,w) {
q[1][x] = por(q[0][x], por(l[x], r[x]));
}
q[2] = q[1];
repeat (x,w) {
if (s[y][x] == 2 and 0 <= x-1 and x+1 < w) {
q[2][x] = por(q[2][x], p[y][x] * q[1][x-1] * q[1][x+1]);
}
if (s[y][x] == 3 and 0 <= x-1 and x+1 < w and y-1 >= 0) {
q[2][x] = por(q[2][x], p[y][x] * q[1][x-1] * q[1][x+1] * dp[y-1][x]);
}
}
dp[y] = q[2];
}
double result = 0; repeat (y,h) repeat (x,w) result += dp[y][x];
cout << result << endl;
return 0;
}