답안 #244035

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
244035 2020-07-02T13:39:01 Z Vimmer Kvalitetni (COCI16_kvalitetni) C++14
12 / 120
9 ms 1932 KB
#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]);

    sort(gr.begin(), gr.end());

    reverse(gr.begin(), gr.end());

    int mx = 0;

    bool gd = 0;

    for (int i = 1; i < sz(gr) && !gd; i++)
    {
        for (int j = 0; j < i && !gd; j++)
        {
            mx = max(mx, j);

            ld cur = gr[j] - gr[i];

            if (cur - need > 0) {gd = 1; gr[j] -= need; need = 0; break;}
              else {gr[j] -= cur; need -= cur;}
        }
    }

    ld sumr = 0;

    for (int j = 0; j <= mx; j++) sumr += gr[j];

    sumr /= ld(mx + 1);

    for (int j = 0; j <= mx; j++) gr[j] = sumr;

    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 Correct 5 ms 512 KB Output is correct
2 Incorrect 5 ms 640 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 620 KB Output is correct
2 Correct 5 ms 640 KB Output is correct
# 결과 실행 시간 메모리 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 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 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1536 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 1932 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 6 ms 1664 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -