結果
問題 | No.1196 A lazy student |
ユーザー |
![]() |
提出日時 | 2020-08-22 15:48:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 201 ms / 1,000 ms |
コード長 | 2,080 bytes |
コンパイル時間 | 1,104 ms |
コンパイル使用メモリ | 97,840 KB |
実行使用メモリ | 12,828 KB |
最終ジャッジ日時 | 2024-10-15 09:58:18 |
合計ジャッジ時間 | 2,732 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <set>#include <string>#include <vector>#include <iostream>#include <algorithm>#include <functional>using namespace std;int main() {cin.tie(0);ios_base::sync_with_stdio(false);int N; long double P, Q, R; string S;cin >> N >> P >> Q >> R >> S;vector<int> node_pos; vector<long double> dp;for (int i = 0; i < N; ++i) {if (i <= N - 3 && S.substr(i, 3) == "YES") {node_pos.push_back(i);dp.push_back(1.0L);}if (i <= N - 2 && S.substr(i, 2) == "NO") {node_pos.push_back(i);dp.push_back(0.0L);}}vector<pair<int, int> > merger;int depth = 0;for (int i = 0; i < N; ++i) {if (S[i] == '(') ++depth;if (S[i] == ')') --depth;if (i <= N - 6 && S.substr(i, 6) == "random") {merger.push_back(make_pair(depth * 3 + 2, i));}if (i <= N - 3 && S.substr(i, 3) == "and" && (i == 0 || i > N - 5 || S.substr(i - 1, 6) != "random")) {merger.push_back(make_pair(depth * 3 + 1, i));}if (i <= N - 2 && S.substr(i, 2) == "or") {merger.push_back(make_pair(depth * 3, i));}}sort(merger.begin(), merger.end(), [](pair<int, int> p1, pair<int, int> p2) { return p1.first != p2.first ? p1.first > p2.first : p1.second < p2.second; });set<int> current;for (int i = 0; i < node_pos.size(); ++i) {current.insert(i);}for (pair<int, int> i : merger) {int ptr = lower_bound(node_pos.begin(), node_pos.end(), i.second) - node_pos.begin();set<int>::iterator it = current.lower_bound(ptr);if (i.first % 3 == 2) {// RANDOMint lp = *it, rp = *(++it);dp[lp] = dp[lp] * dp[rp] * P + (1.0L - dp[lp] * dp[rp]) * Q;current.erase(rp);}if (i.first % 3 == 1) {// ANDint rp = *it, lp = *(--it);dp[lp] = dp[lp] * dp[rp] * (1.0L - R) + (1.0L - dp[lp] * dp[rp]) * R;current.erase(rp);}if (i.first % 3 == 0) {// ORint rp = *it, lp = *(--it);dp[lp] = (1.0L - dp[lp]) * (1.0L - dp[rp]) * R + (1.0L - (1.0L - dp[lp]) * (1.0L - dp[rp])) * (1.0L - R);current.erase(rp);}}long double ans = dp[0];cout << int(ans * 100.0 + 1.0e-15L) << endl;return 0;}