#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#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 F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define N 300101
#define M ll(1e9 + 7)
#define inf 1e9 + 1e9
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef long long ll;
typedef short int si;
typedef pair <int, int> par;
typedef array <int, 2> a2;
//typedef tree <int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
ld z[10000], f[10000];
ll znak[10000];
vector <ll> g[10000];
void dfs(ll v)
{
if (sz(g[v]) == 0) {f[v] = z[0]; return;}
if (znak[v] == 1) f[v] = 1;
vector <ld> gr; gr.clear();
ld sum = 0;
for (auto it : g[v])
{
dfs(it);
gr.pb(f[it]);
sum += f[it];
}
if (znak[v] == 0) {f[v] = min(sum, z[sz(gr) - 1]); return;}
sort(gr.begin(), gr.end());
sum = z[sz(gr) - 1];
for (int i = 0; i < sz(gr); i++)
{
ld cur = sum / ld(sz(gr) - i);
if (gr[i] - cur >= 0)
{
for (int j = i; j < sz(gr); j++) gr[j] = cur;
break;
}
else sum -= gr[i];
}
for (auto it : gr) f[v] *= it;
}
int main()
{
//freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);
ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin >> n;
for (ll i = 0; i < n; i++) cin >> z[i];
string s;
cin >> s;
stack <ll> st;
ll id = 1;
for (ll i = 0; i < sz(s); i++)
{
if (s[i] == '(') {if (id != 1) g[st.top()].pb(id); st.push(id++);}
if (s[i] == ')') st.pop();
if (s[i] == '*') znak[st.top()] = 1;
if (s[i] == '+') znak[st.top()] = 0;
}
dfs(1);
cout << setprecision(6) << fixed;
cout << f[1] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
844 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Runtime error |
8 ms |
2060 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
1792 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
9 ms |
2060 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
7 ms |
1760 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |