結果

問題 No.1196 A lazy student
ユーザー Ricky_ponRicky_pon
提出日時 2020-08-22 15:47:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 1,000 ms
コード長 2,254 bytes
コンパイル時間 2,509 ms
コンパイル使用メモリ 195,768 KB
実行使用メモリ 88,980 KB
最終ジャッジ日時 2024-04-23 10:04:41
合計ジャッジ時間 2,892 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 10 ms
6,944 KB
testcase_09 AC 22 ms
6,940 KB
testcase_10 AC 23 ms
6,940 KB
testcase_11 AC 24 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,944 KB
testcase_15 AC 90 ms
88,980 KB
testcase_16 AC 29 ms
17,844 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define For(i, a, b) for (int(i) = (int)(a); (i) < (int)(b); ++(i))
#define rFor(i, a, b) for (int(i) = (int)(a)-1; (i) >= (int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
#define double long double
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T div_floor(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a >= 0 ? a / b : (a + 1) / b - 1;
}
template <class T>
T div_ceil(T a, T b) {
    if (b < 0) a *= -1, b *= -1;
    return a > 0 ? (a - 1) / b + 1 : a / b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

double p, q, r;

double expr(string &s, int &i);
double term(string &s, int &i);
double factor(string &s, int &i);

double expr(string &s, int &i) {
    double ret = term(s, i);
    while (i < (int)s.size() && s[i] == 'o') {
        i += 2;
        double rhs = term(s, i);
        ret = 1 - (1 - ret) * (1 - rhs);
        ret = (1 - r) * ret + r * (1 - ret);
    }
    return ret;
}

double term(string &s, int &i) {
    double ret = factor(s, i);
    while (i < (int)s.size() && s[i] == 'a') {
        i += 3;
        double rhs = factor(s, i);
        ret = ret * rhs;
        ret = (1 - r) * ret + r * (1 - ret);
    }
    return ret;
}

double factor(string &s, int &i) {
    if (s[i] == '(') {
        ++i;
        double ret = expr(s, i);
        ++i;
        return ret;
    } else if (s[i] == 'r') {
        i += 7;
        double lhs = expr(s, i);
        double rhs = expr(s, i);
        ++i;
        return p * lhs * rhs + q * (1 - lhs * rhs);
    } else if (s[i] == 'Y') {
        i += 3;
        return 1;
    } else {
        i += 2;
        return 0;
    }
}

int main() {
    int n;
    string s;
    cin >> n >> p >> q >> r >> s;
    int i = 0;
    int ans = expr(s, i) * 100;
    cout << ans << "\n";
}
0