結果

問題 No.1196 A lazy student
ユーザー SHIJOUSHIJOU
提出日時 2020-09-22 22:26:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,239 bytes
コンパイル時間 2,826 ms
コンパイル使用メモリ 199,448 KB
実行使用メモリ 19,128 KB
最終ジャッジ日時 2023-09-09 05:03:18
合計ジャッジ時間 5,189 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 19 ms
12,156 KB
testcase_16 AC 10 ms
6,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0xccccccc;
const ll LINF = 0xcccccccccccccccLL;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

#define N 1001000

//head

int n;
float p, q, r;
char s[N];

pair<float, int> Random(int);
pair<float, int> dfs(int, float); 
pair<float, int> calc(int);
int check(int i) {
	if(s[i] == 'N') return 0;
	if(s[i] == 'Y') return 1;
	if(s[i] == 'r') return -1;
	if(s[i] == '(') return 99;
	if(s[i] == ')') return 100;
	return INF;
}

int main() {
	scanf("%d%f%f%f %s", &n, &p, &q, &r, s);
	printf("%d\n", int(calc(0).first*100));
}

pair<float, int> Random(int i) {
	i += 7;
	auto [u1, v1] = calc(i);
	auto [u2, v2] = calc(v1);
	return {u1*u2*p + (1-u1*u2)*q, v2+1};
}

pair<float, int> dfs(int i, float p) {
	if(i == n or check(i) != INF) return {p, i};
	if(s[i] == 'o') {
		auto [u, v] = calc(i+2);
		p = 1-p;
		u = 1-u;
		p *= u;
		u = 1-p;
		return {u*(1-r)+p*r, v};
	}
	int z = check(i += 3);
	if(z == 0) return dfs(i+2, r);
	if(z == 1) return dfs(i+3, p*(1-r)+(1-p)*r);
	if(z == -1) {
		auto [u, v] = Random(i);
		u *= p;
		p = 1-u;
		return dfs(v, u*(1-r)+p*r);
	}
	auto [u, v] = calc(i+1);
	u *= p;
	p = 1-u;
	return dfs(v, u*(1-r)+p*r);
}

pair<float, int> calc(int i) {
	int u = check(i);
	if(u == -1) {
		auto [u, v] = Random(i);
		return dfs(v, u);
	}
	if(u == 0) return dfs(i+2, 0);
	if(u == 1) return dfs(i+3, 1);
	auto [z, v] = calc(i+1);
	return dfs(v+1, z);
}
0