結果

問題 No.1196 A lazy student
ユーザー chocoruskchocorusk
提出日時 2020-08-22 16:41:22
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 68 ms / 1,000 ms
コード長 1,575 bytes
コンパイル時間 1,274 ms
コンパイル使用メモリ 125,564 KB
実行使用メモリ 65,932 KB
最終ジャッジ日時 2024-04-23 10:40:33
合計ジャッジ時間 1,967 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 10 ms
6,944 KB
testcase_09 AC 21 ms
6,944 KB
testcase_10 AC 21 ms
6,940 KB
testcase_11 AC 21 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 68 ms
65,932 KB
testcase_16 AC 27 ms
14,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
double p, q, r;
string s;
double yesno(int&);
double factor(int&);
double calcand(int&);
double expr(int&);
double yesno(int &i){
	if(s[i]=='Y'){
		i+=3;
		return 1;
	}else{
		i+=2;
		return 0;
	}
}
double factor(int &i){
	if(s[i]=='('){
		i++;
		double ret=expr(i);
		i++;
		return ret;
	}else if(s[i]=='r'){
		i+=6;
		i++;
		double ret1=expr(i);
		double ret2=expr(i);
		i++;
		return ret1*ret2*p+(1-ret1*ret2)*q;
	}else{
		return yesno(i);
	}
}
double calcand(int &i){
	double ret=factor(i);
	while(1){
		if(i==n) break;
		if(s[i]=='a'){
			i+=3;
			double ret1=factor(i);
			ret=(1-ret*ret1)*r+ret*ret1*(1-r);
		}else{
			break;
		}
	}
	return ret;
}
double expr(int &i){
	double ret=calcand(i);
	while(1){
		if(i==n) break;
		if(s[i]=='o'){
			i+=2;
			double ret1=calcand(i);
			ret=(1-ret)*(1-ret1)*r+(1-(1-ret)*(1-ret1))*(1-r);
		}else{
			break;
		}
	}
	return ret;
}
int main()
{
	cin>>n>>p>>q>>r>>s;
	int i=0;
	double ans=expr(i)*100;
	cout<<(int)(ans+1e-9)<<endl;
	return 0;
}
0