結果
| 問題 |
No.1196 A lazy student
|
| コンテスト | |
| ユーザー |
Forested
|
| 提出日時 | 2020-10-09 18:10:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 31 ms / 1,000 ms |
| コード長 | 2,506 bytes |
| コンパイル時間 | 1,915 ms |
| コンパイル使用メモリ | 194,908 KB |
| 最終ジャッジ日時 | 2025-01-15 03:41:30 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 14 |
ソースコード
// Template
#include "bits/stdc++.h"
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003LL;
template <typename T>
inline bool chmin(T &x, const T &y) {
if (x > y) {
x = y;
return true;
}
return false;
}
template <typename T>
inline bool chmax(T &x, const T &y) {
if (x < y) {
x = y;
return true;
}
return false;
}
struct IOSET {
IOSET() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
cout << fixed << setprecision(10);
}
} ioset;
// Main
using ld = long double;
ld p, q, r;
ld change(ld x) {
return x * (1 - r) + (1 - x) * r;
}
ld OR(ld x, ld y) {
return change(1 - (1 - x) * (1 - y));
}
ld AND(ld x, ld y) {
return change(x * y);
}
ld random(ld x, ld y) {
return x * y * p + (1 - x * y) * q;
}
using State = string::const_iterator;
ld expr(State &state);
ld term(State &state);
ld rfactor(State &state);
ld factor(State &state);
ld val(State &state);
ld expr(State &state) {
ld x = term(state), res = 0;
if (*state == 'o') {
state += 2;
ld y = expr(state);
res = OR(x, y);
} else {
res = x;
}
return res;
}
ld term(State &state) {
ld x = rfactor(state), res = 0;
if (*state == 'a') {
state += 3;
ld y = term(state);
res = AND(x, y);
} else {
res = x;
}
return res;
}
ld rfactor(State &state) {
ld res = 0;
if (*state == 'r') {
state += 7;
ld x = expr(state);
ld y = expr(state);
res = random(x, y);
} else {
res = factor(state);
}
return res;
}
ld factor(State &state) {
ld res = 0;
if (*state == '(') {
++state;
res = expr(state);
++state;
} else {
res = val(state);
}
return res;
}
ld val(State &state) {
if (*state == 'Y') {
state += 3;
return 1;
} else {
state += 2;
return 0;
}
}
int main() {
int n;
string s;
cin >> n >> p >> q >> r >> s;
State state = s.begin();
cout << (int)(expr(state) * 100) << "\n";
}
Forested