結果

問題 No.1196 A lazy student
ユーザー 沙耶花沙耶花
提出日時 2020-08-22 14:58:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 1,000 ms
コード長 2,028 bytes
コンパイル時間 2,491 ms
コンパイル使用メモリ 203,372 KB
実行使用メモリ 234,808 KB
最終ジャッジ日時 2023-08-05 12:13:12
合計ジャッジ時間 4,078 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 19 ms
4,376 KB
testcase_09 AC 40 ms
5,056 KB
testcase_10 AC 42 ms
5,072 KB
testcase_11 AC 40 ms
5,128 KB
testcase_12 AC 1 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 201 ms
234,808 KB
testcase_16 AC 76 ms
61,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000005

vector<double> n0(int&);
vector<double> n1(int&);
vector<double> n2(int&);
vector<double> n3(int&);

int N;
double P,Q,R;
string S;

vector<double> OR(vector<double> a,vector<double> b){
	vector<double> ans(2,0.0);
	a[0] *= b[0];
	a[1] = 1.0-a[0];
	ans[0] = (1.0-R)*a[0] + R*a[1];
	ans[1] = 1.0-ans[0];
	
	return ans;
}

vector<double> AND(vector<double> a,vector<double> b){
	vector<double> ans(2,0.0);
	a[1] *= b[1];
	a[0] = 1.0-a[1];
	ans[0] = (1.0-R)*a[0] + R*a[1];
	ans[1] = 1.0-ans[0];
	
	return ans;
}

vector<double> RANDOM(vector<double> a,vector<double> b){
	double t = a[1]*b[1];
	vector<double> ans(2,0.0);
	ans[1] = P*t + Q*(1.0-t);
	ans[0] = 1.0-ans[1];
	return ans;
}

vector<double> n0(int &i){
	vector<double> x = n1(i);
	while(true){
		if(i==S.size())return x;
		if(S[i]!='o')return x;
		i++;
		vector<double> y = n1(i);
		x = OR(x,y);
	}	
}

vector<double> n1(int &i){
	vector<double> x = n2(i);
	while(true){
		if(i==S.size())return x;
		if(S[i]!='a')return x;
		i++;
		vector<double> y = n2(i);
		x = AND(x,y);
	}	
}

vector<double> n2(int &i){
	vector<double> x;
	if(S[i]=='('){
		i++;
		x = n0(i);
		i++;
	}
	else{
		x = n3(i);
	}
	return x;
	
}

vector<double> n3(int &i){
	vector<double> x(2,0.0);
	if(S[i]=='Y'){
		x[1] = 1.0;
		i++;
	}
	else if(S[i]=='N'){
		x[0] = 1.0;
		i++;
	}
	else{
		i+=2;
		vector<double> y = n0(i);
		vector<double> z = n0(i);
		x = RANDOM(y,z);
		i++;
	}
	return x;
}

int main(){
	
	cin>>N>>P>>Q>>R;
	
	cin>>S;
	
	{
		string T = "";
		for(int i=0;i<S.size();i++){
			T += S[i];
			if(S[i]=='('||S[i]==')'){
				continue;
			}
			if(S[i]=='r'){
				i+=5;
				continue;
			}
			if(S[i]=='o'||S[i]=='N'){
				i++;
				continue;
			}
			if(S[i]=='Y'||S[i]=='a'){
				i+=2;
				continue;
			}
		}
		
		S = T;
	}
	int j = 0;
	vector<double> ans = n0(j);
	
	cout<<fixed<<setprecision(0)<<floor(ans[1]*100.0)<<endl;
	
	return 0;
}
0