Submission #582273

# Submission time Handle Problem Language Result Execution time Memory
582273 2022-06-23T15:18:05 Z Ronin13 Sirni (COCI17_sirni) C++14
112 / 140
5000 ms 615668 KB
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;

void lastshot(){
    cout << "FUCK THIS SHIT I'M OUT!\n";
}
void debug(){
    cout << "WHAT A STUPID\n";
}

//WELCOME TO PROJECT MAYHEM
// rule #1: You don't ask questions about project MAYHEM
// rule #2: You don't ask questions about project MAYHEM

const int PMAX = 1e7 + 5;
const int NMAX = 2e5 + 1;

int p[PMAX];
int last[PMAX];
vector <vector <int> > g(NMAX);

vector <int>par(NMAX);
vector <int> sz(NMAX);

void make_set(int v){
    par[v] = v;
    sz[v] = 1;
}

int find_set(int v){
    return par[v] == v ? v : par[v] = find_set(par[v]);
}

void union_sets(int a, int b){
    a = find_set(a);
    b = find_set(b);
    if(a != b){
        if(sz[a] < sz[b]) swap(a, b);
        par[b] = a;
        sz[a] += sz[b];
    }
}

int main(){
    int n; cin >> n;
    set <int> st;
    for(int i = 1; i <= n; i++){
        int x; cin >> x;
        st.insert(x);
    }
    int ind = 0;
    for(int to : st){
        p[to] = ++ind;
    }
    int l = 10000001;
    for(int i = 10000001; i >= 1; i--){
        if(p[i]) last[i] = i, l = i;
        else last[i] = l;
    }
   // cout << 1;
    ind = 1;
    vector <pair <ll, pii> > edges;
    for(int to : st){
        int x = last[to + 1];
        if(x < 2 * to && x < 1e7 + 1)
        edges.pb({x - to, {ind, p[x]}});
        for(int i = 2 * to; i <= 1e7; i += to){
            x = last[i];
            if(x > 1e7) break;
            if(x > 1e7 || x >= i + to) continue;
            edges.pb({x - i, {p[x], ind}});
        }
        ind++;
    }
    //cout << 1;
    for(int i = 1; i < ind; i++){
        make_set(i);
    }
    sort(edges.begin(), edges.end());
    ll sum = 0;
    for(auto to : edges){
       // cout << to.f << ' ' << to.s.f << ' ' << to.s.s << "\n";
        int x = to.s.f, y = to.s.s;
        if(find_set(x) == find_set(y)) continue;
        union_sets(x, y);
        sum += to.f;
    }
    cout << sum;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 34 ms 49488 KB Output is correct
2 Correct 84 ms 51952 KB Output is correct
3 Correct 32 ms 49932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 46004 KB Output is correct
2 Correct 238 ms 47320 KB Output is correct
3 Correct 38 ms 49960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 34 ms 49848 KB Output is correct
2 Correct 35 ms 48248 KB Output is correct
3 Correct 33 ms 49904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 71300 KB Output is correct
2 Correct 798 ms 120220 KB Output is correct
3 Correct 345 ms 87072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 70 ms 54588 KB Output is correct
2 Correct 411 ms 115556 KB Output is correct
3 Correct 272 ms 68536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 504 ms 120556 KB Output is correct
2 Correct 1027 ms 186052 KB Output is correct
3 Correct 329 ms 87632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 106 ms 56732 KB Output is correct
2 Correct 957 ms 185136 KB Output is correct
3 Correct 296 ms 87220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 374 ms 123248 KB Output is correct
2 Correct 4672 ms 615668 KB Output is correct
3 Correct 362 ms 123172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 370 ms 123148 KB Output is correct
2 Execution timed out 5115 ms 613628 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 76 ms 85208 KB Output is correct
2 Execution timed out 5105 ms 606252 KB Time limit exceeded
3 Halted 0 ms 0 KB -