結果
問題 | No.1196 A lazy student |
ユーザー |
![]() |
提出日時 | 2020-08-22 14:58:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 284 ms / 1,000 ms |
コード長 | 2,028 bytes |
コンパイル時間 | 2,627 ms |
コンパイル使用メモリ | 200,152 KB |
最終ジャッジ日時 | 2025-01-13 09:02:40 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 14 |
ソースコード
#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; }