# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
202046 | SamAnd | Kvalitetni (COCI16_kvalitetni) | C++17 | 18 ms | 2040 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 m_p make_pair
const int K = 55, N = 1000006;
int k;
int zz[K];
long double z[K];
int n;
char a[N];
int rr[N];
long double solv(int l, int r)
{
if (l + 1 == r - 1)
{
return z[1];
}
vector<pair<int, int> > v;
int ll = l + 1;
while (1)
{
if (ll > r)
break;
v.push_back(m_p(ll, rr[ll]));
ll = rr[ll] + 2;
}
vector<long double> ans;
for (int i = 0; i < v.size(); ++i)
ans.push_back(solv(v[i].first, v[i].second));
char g = a[v[0].second + 1];
if (g == '+')
{
long double yans = 0;
for (int i = 0; i < v.size(); ++i)
yans += ans[i];
return min(yans, z[v.size()]);
}
else
{
long double sum = 0;
for (int i = 0; i < v.size(); ++i)
sum += ans[i];
if (sum > z[v.size()])
{
sort(ans.begin(), ans.end());
for (int i = ans.size() - 1; i >= 0; --i)
{
if (i == 0)
{
for (int j = 0; j < ans.size(); ++j)
ans[j] = (z[v.size()] / (ans.size() - i));
break;
}
if ((sum - (ans.size() - i) * (ans[i] - ans[i - 1])) > z[v.size()])
{
sum = (sum - (ans.size() - i) * (ans[i] - ans[i - 1]));
}
else
{
for (int j = i; j < ans.size(); ++j)
ans[j] = ans[i];
for (int j = i; j < ans.size(); ++j)
ans[j] -= (sum - z[v.size()]) / (ans.size() - i);
break;
}
}
}
long double yans = 1;
for (int i = 0; i < ans.size(); ++i)
yans *= ans[i];
return yans;
}
}
int main()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(9);
scanf("%d", &k);
for (int i = 1; i <= k; ++i)
{
scanf("%d", &zz[i]);
z[i] = zz[i];
}
scanf(" %s", a);
n = strlen(a);
stack<int> s;
for (int i = 0; i < n; ++i)
{
if (a[i] == '(')
{
s.push(i);
}
else if (a[i] == ')')
{
rr[s.top()] = i;
s.pop();
}
}
cout << solv(0, n - 1) << endl;
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... |