結果

問題 No.1196 A lazy student
ユーザー oteraotera
提出日時 2020-08-23 18:51:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 1,000 ms
コード長 1,796 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 128,244 KB
実行使用メモリ 66,068 KB
最終ジャッジ日時 2024-04-23 18:16:54
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 24 ms
5,376 KB
testcase_10 AC 25 ms
5,376 KB
testcase_11 AC 24 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 72 ms
66,068 KB
testcase_16 AC 29 ms
14,388 KB
権限があれば一括ダウンロードができます

ソースコード

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 = term(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.0 - r) * y + r * (1.0 - 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;
        ++ begin;
        return t * p + (1.0 - t) * q;
    } 
    assert(0);
}

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