結果
問題 | No.1196 A lazy student |
ユーザー | capra314cabra |
提出日時 | 2020-08-21 08:51:51 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 77 ms / 1,000 ms |
コード長 | 5,414 bytes |
コンパイル時間 | 1,623 ms |
コンパイル使用メモリ | 175,472 KB |
実行使用メモリ | 28,556 KB |
最終ジャッジ日時 | 2024-10-15 04:51:16 |
合計ジャッジ時間 | 2,563 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,816 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 2 ms
6,820 KB |
testcase_08 | AC | 16 ms
6,816 KB |
testcase_09 | AC | 35 ms
6,820 KB |
testcase_10 | AC | 36 ms
6,820 KB |
testcase_11 | AC | 35 ms
6,816 KB |
testcase_12 | AC | 2 ms
6,820 KB |
testcase_13 | AC | 2 ms
6,820 KB |
testcase_14 | AC | 2 ms
6,816 KB |
testcase_15 | AC | 77 ms
28,556 KB |
testcase_16 | AC | 36 ms
8,112 KB |
ソースコード
#include "bits/stdc++.h" using namespace std; //------------------------------- #define int long long //------------------------------- #define rep(i, n) for (int i = 0; i < (n); i++) #define FOR(i, a, b) for (int i = (a), int size##i = (b); i < size##i; i++) #define FORR(i, a, b) for (int i = (a); i >= (b); i--) #define all(v) v.begin(), v.end() #define tint(str) atoi(str.c_str()) #define tstr(num) to_string(num) #define prt(x) cout << x << endl #ifdef DEBUG #define dbg(x) cout << "[DBG] " << x << endl #else #define dbg(x) #endif typedef long long ll; typedef long double ld; typedef pair<int, int> PII; typedef vector<int> VI; typedef vector<vector<int>> VVI; template <typename T> using PQ = priority_queue<T, vector<T>, greater<T>>; template <typename T> using RPQ = priority_queue<T, vector<T>, less<T>>; int dx[4] = {0, 1, 0, -1}; int dy[4] = {1, 0, -1, 0}; //------------------------------- int n; double p, q, r; string s; int cr = 0; double ret = 0; enum Status { EXPR, EXPR_SND, EXPR_TRD, TERM, TERM_SND, TERM_TRD, FACTOR, FACTOR_BR, FACTOR_RND_FST, FACTOR_RND_SND }; stack<pair<Status, double>> items; char gnt() { if (cr == s.size()) { return 0; } switch (s[cr]) { case '(': cr++; return '('; case ')': cr++; return ')'; case ' ': cr++; return gnt(); case 'Y': cr += 3; return 'Y'; case 'N': cr += 2; return 'N'; case 'r': cr += 6; return 'r'; case 'a': cr += 3; return 'a'; case 'o': cr += 2; return 'o'; default: return -1; } } inline double myrand(double a, double b) { return a * b * p + (1 - a * b) * q; } inline double myor(double a, double b) { return (a + b - a * b) * (1 - r) + ((1 - a) * (1 - b)) * r; } inline double myand(double a, double b) { return a * b * (1 - r) + (1 - a * b) * r; } signed main() { char c; cin >> n >> p >> q >> r; getline(cin, s); getline(cin, s); rep (i, s.size()) { if (s[i] == ' ') { throw 1; } } items.push({EXPR, -1}); while (!items.empty()) { auto itm = items.top(); items.pop(); switch (itm.first) { case EXPR: { dbg("Visit EXPR"); items.push({EXPR_SND, -1}); items.push({TERM, -1}); continue; } case EXPR_SND: { dbg("Visit EXPR_SND"); int prev = cr; if (gnt() == 'o') { items.push({EXPR_TRD, ret}); items.push({TERM, -1}); } else { cr = prev; } continue; } case EXPR_TRD: { dbg("Visit EXPR_TRD"); items.push({EXPR_SND, -1}); ret = myor(itm.second, ret); continue; } case TERM: { dbg("Visit TREM"); items.push({TERM_SND, -1}); items.push({FACTOR, -1}); continue; } case TERM_SND: { dbg("Visit TERM_SND"); int prev = cr; if (gnt() == 'a') { items.push({TERM_TRD, ret}); items.push({FACTOR, -1}); } else { cr = prev; } continue; } case TERM_TRD: { dbg("Visit TERM_TRD"); items.push({TERM_SND, -1}); ret = myand(itm.second, ret); continue; } case FACTOR: { dbg("Visit FACTOR"); char c = gnt(); switch (c) { case 'Y': ret = 1; continue; case 'N': ret = 0; continue; case '(': { items.push({FACTOR_BR, -1}); items.push({EXPR, -1}); continue; } case 'r': { gnt(); items.push({FACTOR_RND_FST, -1}); items.push({EXPR, -1}); continue; } default: { cout << "WTF " << c << endl; throw -1; } } } case FACTOR_BR: { dbg("Visit FACTOR_BR"); gnt(); continue; } case FACTOR_RND_FST: { dbg("Visit FACTOR_RND_FST"); items.push({FACTOR_RND_SND, ret}); items.push({EXPR, -1}); continue; } case FACTOR_RND_SND: { dbg("Visit FACTOR_RND_SND"); gnt(); ret = myrand(ret, itm.second); continue; } } } cout << (int)(ret * 100) << endl; return 0; }