제출 #1243048

#제출 시각아이디문제언어결과실행 시간메모리
1243048matsakyannnNile (IOI24_nile)C++20
23 / 100
2095 ms10928 KiB
#include <bits/stdc++.h>
using namespace std;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x << ' '; print(x); cerr << endl;
#else
#define dbg(x)
#endif 

void print(int x) {cerr << x;}
void print(long long x) {cerr << x;}
void print(char x) {cerr << x;}
void print(string x) {cerr << x;}
void print(double x) {cerr << x;}
template <class T> void print(vector <T> x);
template <class T> void print(set <T> x);
template <class T> void print(multiset <T> x);
template <class T, class V> void print(pair <T, V> x);
template <class T, class V> void print(map <T, V> x);
template <class T> void print(vector <T> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
template <class T> void print(set <T> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
template <class T> void print(multiset <T> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}
template <class T, class V> void print(pair <T, V> x) {cerr << "{"; print(x.first); cerr << ' '; print(x.second); cerr << "}";}
template <class T, class V> void print(map <T, V> x) {cerr << "[ "; for(auto i : x) {print(i); cerr << ' ';} cerr << "]";}

#define ll long long
#define pb push_back
#define ppb pop_back
#define PII pair <int, int>
#define PLL pair <ll, ll>
#define all(v) (v).begin(), (v).end()
#define OK cerr << "OK\n";
#define MP make_pair

const int N0 = 1e5 + 5, inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

int n, q;
struct ber{
    ll w, a, b;
};
bool operator<(ber x, ber y){
    return x.w < y.w;
}
vector <ber> a;

struct DisjointSetUnion{
    int p[N0], sz[N0], mn[N0];

    void init(){
        for(int i = 0; i < n; i++){
            sz[i] = 1;
            p[i] = i;
            mn[i] = a[i].a - a[i].b;
        }
    }

    int find(int x){
        if(p[x] != x) p[x] = find(p[x]);
        return p[x];
    }

    void unite(int x, int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(sz[x] < sz[y]) swap(x, y);
        p[y] = x;
        sz[x] += sz[y];
        mn[x] = min(mn[x], mn[y]);
    }
} dsu;

vector <ll> calculate_costs(vector <int> W, vector <int> A, vector <int> B, vector <int> E){
    n = W.size();
    q = E.size();
    ll Bsum = 0;
    for(int i = 0; i < n; i++){
        a.pb({W[i], A[i], B[i]});
        Bsum += B[i];
    }
    sort(all(a));

    vector <ll> answ;
    for(int ii = 0; ii < q; ii++){
        dsu.init();
        ll d = E[ii];
        for(int i = 0; i < n - 1; i++){
            if(a[i + 1].w - a[i].w <= d) dsu.unite(i, i + 1);
        }
        set <int> fathers;
        for(int i = 0; i < n; i++){
            fathers.insert(dsu.p[i]);
        }

        ll cost = Bsum; 
        for(int i : fathers){
            if(dsu.sz[i] % 2 == 0) continue;
            cost += dsu.mn[i];
        }
        answ.pb(cost);
    }
    return answ;
}
#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...