結果
問題 | No.1196 A lazy student |
ユーザー |
![]() |
提出日時 | 2020-08-22 16:51:54 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 207 ms / 1,000 ms |
コード長 | 2,352 bytes |
コンパイル時間 | 1,400 ms |
コンパイル使用メモリ | 98,756 KB |
実行使用メモリ | 12,832 KB |
最終ジャッジ日時 | 2024-10-15 10:54:05 |
合計ジャッジ時間 | 3,074 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <set>#include <string>#include <vector>#include <iostream>#include <algorithm>#include <functional>using namespace std;const __uint128_t D = 1000LL << 49;__uint128_t division(__uint128_t x) {if (x % (D * 1000) == 0) return x / (D * 1000);__uint128_t g = x / (D * 1000);if (g % (D / 1000) == 0) ++g;return g;}int main() {cin.tie(0);ios_base::sync_with_stdio(false);int N; long double sp, sq, sr; string S;cin >> N >> sp >> sq >> sr >> S;__uint128_t P = sp * 1000, Q = sq * 1000, R = sr * 1000;vector<int> node_pos; vector<__uint128_t> 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(D);}if (i <= N - 2 && S.substr(i, 2) == "NO") {node_pos.push_back(i);dp.push_back(0);}}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] = division(dp[lp] * dp[rp] * P + (D * D - dp[lp] * dp[rp]) * Q);current.erase(rp);}if (i.first % 3 == 1) {// ANDint rp = *it, lp = *(--it);dp[lp] = division(dp[lp] * dp[rp] * (1000 - R) + (D * D - dp[lp] * dp[rp]) * R);current.erase(rp);}if (i.first % 3 == 0) {// ORint rp = *it, lp = *(--it);dp[lp] = division((D - dp[lp]) * (D - dp[rp]) * R + (D * D - (D - dp[lp]) * (D - dp[rp])) * (1000 - R));current.erase(rp);}}__uint128_t ans = dp[0];cout << int(ans / (D / 100)) << endl;return 0;}