結果

問題 No.309 シャイな人たち (1)
ユーザー kimiyukikimiyuki
提出日時 2015-12-02 20:11:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,235 bytes
コンパイル時間 673 ms
コンパイル使用メモリ 73,788 KB
実行使用メモリ 4,356 KB
最終ジャッジ日時 2023-10-12 09:02:54
合計ジャッジ時間 1,507 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#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);
}
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];
    printf("%.12lf\n", result);
    return 0;
}
0