Submission #98536

#TimeUsernameProblemLanguageResultExecution timeMemory
98536dalgerokKvalitetni (COCI16_kvalitetni)C++17
120 / 120
32 ms26412 KiB
#include<bits/stdc++.h> using namespace std; const int N = 1e6 + 100; int n, op[N]; vector < int > g[N]; double a[N], z[51]; inline double add(vector < int > &v){ double sum = 0; for(int i = 0; i < (int)v.size(); i++){ sum += a[v[i]]; } return min(sum, z[(int)v.size()]); } inline bool cmp(int x, int y){ return a[x] < a[y]; } inline double mult(vector < int > &v){ sort(v.begin(), v.end(), cmp); double sum = z[(int)v.size()], res = 1; for(int i = 0; i < (int)v.size(); i++){ double mn = min(a[v[i]], sum / (double)((int)v.size() - i)); res *= mn; sum -= mn; } return res; } int main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin >> n; for(int i = 1; i <= n; i++){ cin >> z[i]; } string s; cin >> s; stack < int > q; int cur = 0; for(auto it : s){ if(it == '('){ if(!q.empty()){ g[q.top()].push_back(cur); } q.push(cur++); } else if(it == ')'){ int x = q.top(); q.pop(); if(g[x].empty()){ a[x] = z[1]; } else{ a[x] = (op[x] == 1 ? add(g[x]) : mult(g[x])); } } else if(it == '+'){ op[q.top()] = 1; } else if(it == '*'){ op[q.top()] = 2; } } cout << fixed << setprecision(6) << a[0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...