結果

問題 No.1196 A lazy student
ユーザー ForestedForested
提出日時 2020-10-09 18:10:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 1,000 ms
コード長 2,506 bytes
コンパイル時間 2,037 ms
コンパイル使用メモリ 199,676 KB
実行使用メモリ 35,140 KB
最終ジャッジ日時 2023-09-27 12:44:48
合計ジャッジ時間 3,652 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
    if (x > y) {
        x = y;
        return true;
    }
    return false;
}
template <typename T> 
inline bool chmax(T &x, const T &y) {
    if (x < y) {
        x = y;
        return true;
    }
    return false;
}
struct IOSET {
    IOSET() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
    }
} ioset;


// Main
using ld = long double;

ld p, q, r;

ld change(ld x) {
    return x * (1 - r) + (1 - x) * r;
}

ld OR(ld x, ld y) {
    return change(1 - (1 - x) * (1 - y));
}

ld AND(ld x, ld y) {
    return change(x * y);
}

ld random(ld x, ld y) {
    return x * y * p + (1 - x * y) * q;
}


using State = string::const_iterator;
ld expr(State &state);
ld term(State &state);
ld rfactor(State &state);
ld factor(State &state);
ld val(State &state); 

ld expr(State &state) {
    ld x = term(state), res = 0;
    if (*state == 'o') {
        state += 2;
        ld y = expr(state);
        res = OR(x, y);
    } else {
        res = x;
    }
    return res;
}

ld term(State &state) {
    ld x = rfactor(state), res = 0;
    if (*state == 'a') {
        state += 3;
        ld y = term(state);
        res = AND(x, y);
    } else {
        res = x;
    }
    return res;
}

ld rfactor(State &state) {
    ld res = 0;
    if (*state == 'r') {
        state += 7;
        ld x = expr(state);
        ld y = expr(state);
        res = random(x, y);
    } else {
        res = factor(state);
    }
    return res;
}

ld factor(State &state) {
    ld res = 0;
    if (*state == '(') {
        ++state;
        res = expr(state);
        ++state;
    } else {
        res = val(state);
    }
    return res;
}

ld val(State &state) {
    if (*state == 'Y') {
        state += 3;
        return 1;
    } else {
        state += 2;
        return 0;
    }
}


int main() {
    int n;
    string s;
    cin >> n >> p >> q >> r >> s;
    State state = s.begin();
    cout << (int)(expr(state) * 100) << "\n";
}
0