#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;}
ld need = max(ld(0), sum - z[sz(gr) - 1]) / ld(sz(gr));
sort(gr.begin(), gr.end());
reverse(gr.begin(), gr.end());
int j = 0, i = 0;
while (i < sz(gr) && j < sz(gr))
{
while (j < sz(gr) && (i + 1 == sz(gr) || gr[i + 1] < gr[i])) {gr[i] -= need; j++;}
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
512 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
6 ms |
768 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
7 ms |
1664 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |