Submission #1099761

# Submission time Handle Problem Language Result Execution time Memory
1099761 2024-10-12T05:12:10 Z model_code Nile (IOI24_nile) C++17
32 / 100
108 ms 11288 KB
// incorrect/hazem_A2B1_set_nlogn.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);
    for(int i = 0; i < n; i++)
        w[i] = W[ordW[i]];

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

    set<int> act;
    vector<int> len(n);
    long long tot = 0;
    for(int i = 0; i < n; i++){
        act.insert(i);
        len[i] = 1;
        tot += 1;
    }
    auto mrg = [&](int i){
        int j = *prev(act.upper_bound(i));
        int k = i + 1;
        tot -= len[j] % 2;
        tot -= len[k] % 2;
        act.erase(k);
        len[j] += len[k];
        tot += len[j] % 2;
    };

    vector<long long> R(q, n);
    for(int i = 0; i < q; i++){
        while(!edges.empty() && edges.back()[0] <= E[ordE[i]]){
            auto [_, x] = edges.back(); edges.pop_back();
            mrg(x);
        }
        R[ordE[i]] += tot;
    }
    return R;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 9412 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 9424 KB Output is correct
2 Correct 56 ms 9408 KB Output is correct
3 Correct 75 ms 9412 KB Output is correct
4 Correct 65 ms 9416 KB Output is correct
5 Correct 65 ms 9412 KB Output is correct
6 Correct 77 ms 9412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 9424 KB Output is correct
2 Correct 56 ms 9408 KB Output is correct
3 Correct 75 ms 9412 KB Output is correct
4 Correct 65 ms 9416 KB Output is correct
5 Correct 65 ms 9412 KB Output is correct
6 Correct 77 ms 9412 KB Output is correct
7 Correct 73 ms 11204 KB Output is correct
8 Correct 77 ms 11204 KB Output is correct
9 Correct 89 ms 11204 KB Output is correct
10 Correct 89 ms 11284 KB Output is correct
11 Correct 92 ms 11208 KB Output is correct
12 Correct 93 ms 11208 KB Output is correct
13 Correct 94 ms 11208 KB Output is correct
14 Correct 81 ms 11288 KB Output is correct
15 Correct 108 ms 11208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -