Submission #98536

# Submission time Handle Problem Language Result Execution time Memory
98536 2019-02-23T21:44:05 Z dalgerok Kvalitetni (COCI16_kvalitetni) C++17
120 / 120
32 ms 26412 KB
#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 time Memory Grader output
1 Correct 22 ms 23808 KB Output is correct
2 Correct 24 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 23936 KB Output is correct
2 Correct 25 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 24 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 24032 KB Output is correct
2 Correct 24 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23928 KB Output is correct
2 Correct 21 ms 23936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23936 KB Output is correct
2 Correct 23 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23892 KB Output is correct
2 Correct 27 ms 25220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24440 KB Output is correct
2 Correct 31 ms 25360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 24972 KB Output is correct
2 Correct 31 ms 26412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24696 KB Output is correct
2 Correct 32 ms 26132 KB Output is correct