# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
582283 | 2022-06-23T15:29:22 Z | Ronin13 | Sirni (COCI17_sirni) | C++14 | 5000 ms | 608700 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]; int par[NMAX]; 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(){ ios_base::sync_with_stdio(false); cin.tie(0); 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 = 10000000; 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(int i = 0; i < edges.size(); i++){ // cout << to.f << ' ' << to.s.f << ' ' << to.s.s << "\n"; int x = edges[i].s.f, y = edges[i].s.s; if(find_set(x) == find_set(y)) continue; union_sets(x, y); sum += edges[i].f; } cout << sum; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 43348 KB | Output is correct |
2 | Correct | 76 ms | 45592 KB | Output is correct |
3 | Correct | 29 ms | 43724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 39852 KB | Output is correct |
2 | Correct | 254 ms | 41132 KB | Output is correct |
3 | Correct | 33 ms | 43680 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 43648 KB | Output is correct |
2 | Correct | 36 ms | 42064 KB | Output is correct |
3 | Correct | 29 ms | 43684 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 231 ms | 64584 KB | Output is correct |
2 | Correct | 775 ms | 113312 KB | Output is correct |
3 | Correct | 298 ms | 79944 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 52 ms | 48320 KB | Output is correct |
2 | Correct | 428 ms | 108856 KB | Output is correct |
3 | Correct | 220 ms | 62200 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 569 ms | 113668 KB | Output is correct |
2 | Correct | 1004 ms | 179120 KB | Output is correct |
3 | Correct | 324 ms | 80676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 100 ms | 50236 KB | Output is correct |
2 | Correct | 910 ms | 178368 KB | Output is correct |
3 | Correct | 273 ms | 80288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 285 ms | 116164 KB | Output is correct |
2 | Correct | 4640 ms | 608700 KB | Output is correct |
3 | Correct | 347 ms | 116160 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 311 ms | 116320 KB | Output is correct |
2 | Execution timed out | 5060 ms | 606988 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 80 ms | 78704 KB | Output is correct |
2 | Execution timed out | 5048 ms | 599440 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |