結果
問題 | No.1196 A lazy student |
ユーザー |
![]() |
提出日時 | 2020-08-22 15:46:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 136 ms / 1,000 ms |
コード長 | 2,125 bytes |
コンパイル時間 | 1,566 ms |
コンパイル使用メモリ | 168,860 KB |
実行使用メモリ | 113,236 KB |
最終ジャッジ日時 | 2024-10-15 09:55:29 |
合計ジャッジ時間 | 2,582 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-12; double number(string &S, int &p, double P, double Q, double R); double factor(string &S, int &p, double P, double Q, double R); double term1(string &S, int &p, double P, double Q, double R); double term2(string &S, int &p, double P, double Q, double R); double expression(string &S, int &p, double P, double Q, double R); double number(string &S, int &p, double P, double Q, double R){ if (S[p] == 'Y'){ p++; return 1; } else { p++; return 0; } } double factor(string &S, int &p, double P, double Q, double R){ if (S[p] == '('){ p++; double ans = expression(S, p, P, Q, R); p++; return ans; } else { return number(S, p, P, Q, R); } } double term1(string &S, int &p, double P, double Q, double R){ if (S[p] == 'r'){ p += 2; double x = expression(S, p, P, Q, R); double y = expression(S, p, P, Q, R); p++; return x * y * P + (1 - x * y) * Q; } else { return factor(S, p, P, Q, R); } } double term2(string &S, int &p, double P, double Q, double R){ double ans = term1(S, p, P, Q, R); while (1){ if (S[p] == 'a'){ p++; double tmp = term1(S, p, P, Q, R); ans = ans * tmp * (1 - R) + (1 - ans * tmp) * R; } else { break; } } return ans; } double expression(string &S, int &p, double P, double Q, double R){ double ans = term2(S, p, P, Q, R); while (1){ if (S[p] == 'o'){ p++; double tmp = term2(S, p, P, Q, R); ans = (1 - (1 - ans) * (1 - tmp)) * (1 - R) + (1 - ans) * (1 - tmp) * R; } else { break; } } return ans; } int main(){ int N; cin >> N; double P, Q, R; cin >> P >> Q >> R; string S; cin >> S; string T; for (int i = 0; i < N; i++){ char c = S[i]; T += c; if (c == 'o'){ i++; } if (c == 'a'){ i += 2; } if (c == 'r'){ i += 5; } if (c == 'Y'){ i += 2; } if (c == 'N'){ i++; } } T += '$'; int p = 0; double ans = expression(T, p, P, Q, R); cout << (int) (ans * 100 + EPS) << endl; }