Submission #1099782

# Submission time Handle Problem Language Result Execution time Memory
1099782 2024-10-12T05:16:18 Z model_code Nile (IOI24_nile) C++17
67 / 100
2000 ms 14280 KB
// time_limit/hazem_slow_q_times_CC.cpp

#include "bits/stdc++.h"
#include "nile.h"
using namespace std;

const int INF = 1e9;

vector<long long> calculate_costs(vector<int> W, vector<int> A, vector<int> B, vector<int> E) {
    int n = W.size();
    int q = E.size();

    vector<int> ordW(n);
    iota(ordW.begin() ,ordW.end() ,0);
    sort(ordW.begin() ,ordW.end() ,[&](int i ,int j){
        return W[i] < W[j];
    });
    vector <int> ordE(q);
    iota(ordE.begin() ,ordE.end() ,0);
    sort(ordE.begin() ,ordE.end() ,[&](int i ,int j){
        return E[i] < E[j];
    });
    vector<int> w(n), c(n);
    for(int i = 0; i < n; i++){
        int j = ordW[i];
        w[i] = W[j];
        c[i] = A[j] - B[j];
    }

    vector<array<int, 3>> edges;
    for(int i = 0; i < n; i++){
        if(i+1 < n) edges.push_back({w[i+1] - w[i], i, 1});
        if(i+2 < n) edges.push_back({w[i+2] - w[i], i, 0});
    }
    sort(edges.rbegin(), edges.rend());

    set<int> act;
    vector<int> len(n);
    vector<array<int, 3>> mnc(n);
    for(int i = 0; i < n; i++){
        act.insert(i);
        len[i] = 1;
        mnc[i] = {INF, INF, INF};
        mnc[i][i % 2] = c[i];
    }
    auto cost = [&](int i){
        int idx = mnc[i][i % 2] < mnc[i][2]? (i % 2) : 2;
        return mnc[i][idx] * (len[i] % 2);
    };
    auto mrg = [&](int i){
        int j = *prev(act.upper_bound(i));
        int k = i + 1;
        act.erase(k);
        len[j] += len[k];
        for(int p = 0; p < 3; p++)
            mnc[j][p] = min(mnc[j][p], mnc[k][p]);
    };
    auto upd = [&](int i){
        int j = *prev(act.upper_bound(i));
        mnc[j][2] = min(mnc[j][2], c[i]);
    };
    auto calc = [&](){
        long long tot = 0;
        for(int i : act)
            tot += cost(i);
        return tot;
    };

    vector<long long> R(q, accumulate(B.begin(), B.end(), 0LL));
    for(int i = 0; i < q; i++){
        while(!edges.empty() && edges.back()[0] <= E[ordE[i]]){
            auto [_, x, t] = edges.back(); edges.pop_back();
            if(t) mrg(x);
            else  upd(x + 1);
        }
        R[ordE[i]] += calc();
    }
    return R;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 12708 KB Output is correct
2 Correct 60 ms 12480 KB Output is correct
3 Correct 58 ms 12480 KB Output is correct
4 Correct 62 ms 12480 KB Output is correct
5 Correct 56 ms 12480 KB Output is correct
6 Correct 56 ms 12484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 12684 KB Output is correct
2 Correct 64 ms 12880 KB Output is correct
3 Correct 87 ms 13000 KB Output is correct
4 Correct 86 ms 12328 KB Output is correct
5 Correct 75 ms 12328 KB Output is correct
6 Correct 97 ms 12500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 66 ms 12708 KB Output is correct
8 Correct 60 ms 12480 KB Output is correct
9 Correct 58 ms 12480 KB Output is correct
10 Correct 62 ms 12480 KB Output is correct
11 Correct 56 ms 12480 KB Output is correct
12 Correct 56 ms 12484 KB Output is correct
13 Correct 59 ms 12684 KB Output is correct
14 Correct 64 ms 12880 KB Output is correct
15 Correct 87 ms 13000 KB Output is correct
16 Correct 86 ms 12328 KB Output is correct
17 Correct 75 ms 12328 KB Output is correct
18 Correct 97 ms 12500 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 2 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 672 KB Output is correct
25 Correct 77 ms 12472 KB Output is correct
26 Correct 75 ms 12484 KB Output is correct
27 Correct 97 ms 12488 KB Output is correct
28 Correct 102 ms 12616 KB Output is correct
29 Correct 87 ms 12380 KB Output is correct
30 Correct 110 ms 12340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 12684 KB Output is correct
2 Correct 64 ms 12880 KB Output is correct
3 Correct 87 ms 13000 KB Output is correct
4 Correct 86 ms 12328 KB Output is correct
5 Correct 75 ms 12328 KB Output is correct
6 Correct 97 ms 12500 KB Output is correct
7 Execution timed out 2060 ms 14280 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 2 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 66 ms 12708 KB Output is correct
9 Correct 60 ms 12480 KB Output is correct
10 Correct 58 ms 12480 KB Output is correct
11 Correct 62 ms 12480 KB Output is correct
12 Correct 56 ms 12480 KB Output is correct
13 Correct 56 ms 12484 KB Output is correct
14 Correct 59 ms 12684 KB Output is correct
15 Correct 64 ms 12880 KB Output is correct
16 Correct 87 ms 13000 KB Output is correct
17 Correct 86 ms 12328 KB Output is correct
18 Correct 75 ms 12328 KB Output is correct
19 Correct 97 ms 12500 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 1 ms 604 KB Output is correct
22 Correct 2 ms 604 KB Output is correct
23 Correct 2 ms 604 KB Output is correct
24 Correct 2 ms 604 KB Output is correct
25 Correct 2 ms 672 KB Output is correct
26 Correct 77 ms 12472 KB Output is correct
27 Correct 75 ms 12484 KB Output is correct
28 Correct 97 ms 12488 KB Output is correct
29 Correct 102 ms 12616 KB Output is correct
30 Correct 87 ms 12380 KB Output is correct
31 Correct 110 ms 12340 KB Output is correct
32 Execution timed out 2060 ms 14280 KB Time limit exceeded
33 Halted 0 ms 0 KB -