結果

問題 No.1196 A lazy student
ユーザー 👑 kmjpkmjp
提出日時 2020-08-25 00:09:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 1,000 ms
コード長 1,653 bytes
コンパイル時間 1,849 ms
コンパイル使用メモリ 196,192 KB
実行使用メモリ 51,692 KB
最終ジャッジ日時 2024-04-24 04:02:38
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
double P,Q,R;
string S,T;
char* C;


double expression();

double exp2() {
	if(*C=='Y') {
		C++;
		return 1;
	}
	if(*C=='N') {
		C++;
		return 0;
	}
	if(*C=='(') {
		C++;
		double A=expression();
		C++;
		return A;
	}
	
	C++;
	double A=expression();
	double B=expression();
	C++;
	return A*B*P+(1-A)*(1-B)*Q;
}

double exp1() {
	double A=exp2();
	while(*C=='A') {
		C++;
		double B=exp1();
		A=A*B;
		A=R*A+(1-R)*(1-A);
	}
	return A;
}
double expression() {
	double A=exp1();
	while(*C=='O') {
		C++;
		double B=exp1();
		A=1-(1-A)*(1-B);
		A=R*A+(1-R)*(1-A);
	}
	return A;
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	cin>>P>>Q>>R;
	cin>>S;
	FOR(i,N) {
		if(S[i]=='Y') T+='Y';
		else if(S[i]=='N') T+='N';
		else if(S[i]=='(') T+="(";
		else if(S[i]==')') T+=")";
		if(S[i]=='a') {
			T+='A';
			i+=2;
		}
		else if(S[i]=='o') {
			T+='O';
			i+=1;
		}
		else if(S[i]=='r') {
			T+='R';
			i+=6;
		}
	}
	C=&T[0];
	_P("%.12lf\n",floor(expression()*100));
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0