# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
443551 | penguinhacker | Kvalitetni (COCI16_kvalitetni) | C++14 | 9 ms | 1240 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ar array
int n, z[50], si;
string s;
double solve() {
assert(s[si++]=='(');
if (s[si]=='?') {
si+=2;
return z[0];
}
vector<double> v;
char op='-';
while(1) {
v.push_back(solve());
char cur=s[si++];
if (cur==')')
break;
op=cur;
}
assert(v.size()>=2&&op=='+'||op=='*');
if (op=='+')
return min((double)z[v.size()-1], accumulate(v.begin(), v.end(), 0.0));
double lb=0, rb=z[v.size()-1];
for (int k=0; k<40; ++k) {
double mid=(lb+rb)/2;
double sum=0;
for (double i : v)
sum+=min(i, mid);
if (sum<=z[v.size()-1])
lb=mid;
else
rb=mid;
}
double p=1;
for (double i : v)
p*=min(i, lb);
return p;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i=0; i<n; ++i)
cin >> z[i];
cin >> s;
cout << fixed << setprecision(3) << solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |