結果

問題 No.1196 A lazy student
ユーザー oteraotera
提出日時 2020-08-23 18:44:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 1,789 bytes
コンパイル時間 1,238 ms
コンパイル使用メモリ 127,296 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-23 18:15:29
合計ジャッジ時間 4,305 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<cassert>
#include <cctype>
using namespace std;
typedef long double ld;

typedef string::const_iterator State;
class ParseError {};

ld p, q, r; 
string s;

ld expr(State &begin);
ld term(State &begin);
ld factor(State &begin);

ld expr(State &begin) {
    ld r1 = term(begin);
    while(begin != s.end() and *begin == 'o') {
        begin += 2;
        ld r2 = factor(begin);
        ld y = 1 - (1 - r1) * (1 - r2);
        r1 = (1 - r) * y + r * (1 - y);
    }
    return r1;
}

ld term(State &begin) {
    ld r1 = factor(begin);
    while(begin != s.end() and *begin == 'a') {
        begin += 3;
        ld r2 = factor(begin);
        ld y = r1 * r2;
        r1 = (1 - r) * y + r * (1 - y);
    }
    return r1;
}

ld factor(State &begin) {
    if(*begin == 'Y') {
        begin += 3;
        return 1.0;
    } 
    if(*begin == 'N') {
        begin += 2;
        return 0.0;
    }
    if(*begin == '(') {
        ++ begin;
        ld ret = expr(begin);
        ++ begin;
        return ret;
    } 
    if(*begin == 'r') {
        begin += 7;
        ld r1 = expr(begin);
        ld r2 = expr(begin);
        ld t = r1 * r2;
        return t * p + (1 - t) * q;
        ++ begin;
    } 
    assert(0);
}

int main() {
    int n;
    cin >> p >> q >> r;
    getline(cin, s);
    State begin = s.begin();
    ld ret = expr(begin);
    cout << ceil(100 * ret) << endl;
}
0