#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define ft first
#define sd second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define i2 array<int,2>
#define PB push_back
#define pdi pair<ld,int>
using namespace std;
typedef long double ld;
const int N = 110;
const int oo = 2e9;
const int md = int(1e9) + 7;
const ld E = 1e-9; // 1e-12
string s;
int n, z[N];
pdi rec(int lf){
vector<ld> vc;
vc.clear();
char tp = '_';
int ps = lf + 1;
if (s[ps] == '?')
return {ld(z[1]), ps + 1};
while (1){
if (s[ps] == ')') break;
if (s[ps] == '('){
pdi get = rec(ps);
vc.PB(get.ft);
ps = get.sd + 1;
} else tp = s[ps++];
}
assert(sz(vc) > 1);
if (tp == '+'){
ld sum = 0;
for (ld cr : vc){
sum += cr;
sum = min(sum, ld(z[sz(vc)]));
}
return {sum, ps};
} else {
sort(all(vc));
int cnt = 0;
while (1){
ld med = z[sz(vc)];
for (int i = 0; i < cnt; i++)
med -= vc[i];
med /= (ld(sz(vc)) - ld(cnt));
int nw = cnt;
for (int i = cnt; i < sz(vc); i++)
if (vc[i] + E < med)
nw++;
else break;
if (nw == cnt) break;
cnt = nw;
}
ld med = z[sz(vc)];
for (int i = 0; i < cnt; i++)
med -= vc[i];
med /= (ld(sz(vc)) - ld(cnt));
ld res = 1.0;
for (int i = 0; i < sz(vc); i++)
res *= min(vc[i], med);
return {res, ps};
}
// return {res, ps};
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> n;
for (int i = 1; i <= n; i++)
cin >> z[i];
cin >> s;
cout << fixed << setprecision(10) << rec(0).ft << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
6 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
9 ms |
928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
9 ms |
908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
896 KB |
Output is correct |
2 |
Correct |
12 ms |
1292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
640 KB |
Output is correct |
2 |
Correct |
10 ms |
1292 KB |
Output is correct |