# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
582285 | 2022-06-23T15:32:28 Z | Ronin13 | Sirni (COCI17_sirni) | C++14 | 5000 ms | 608676 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; int cnt = 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(cnt == ind - 1) break; if(find_set(x) == find_set(y)) continue; union_sets(x, y); cnt++; sum += edges[i].f; } cout << sum; return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 43272 KB | Output is correct |
2 | Correct | 81 ms | 45592 KB | Output is correct |
3 | Correct | 28 ms | 43732 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 39868 KB | Output is correct |
2 | Correct | 240 ms | 41016 KB | Output is correct |
3 | Correct | 32 ms | 43684 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 27 ms | 43556 KB | Output is correct |
2 | Correct | 27 ms | 41944 KB | Output is correct |
3 | Correct | 28 ms | 43568 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 237 ms | 64632 KB | Output is correct |
2 | Correct | 744 ms | 113352 KB | Output is correct |
3 | Correct | 356 ms | 79932 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 53 ms | 48320 KB | Output is correct |
2 | Correct | 430 ms | 108844 KB | Output is correct |
3 | Correct | 229 ms | 62132 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 505 ms | 113584 KB | Output is correct |
2 | Correct | 979 ms | 179232 KB | Output is correct |
3 | Correct | 339 ms | 80720 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 93 ms | 50216 KB | Output is correct |
2 | Correct | 941 ms | 178352 KB | Output is correct |
3 | Correct | 291 ms | 80344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 305 ms | 116240 KB | Output is correct |
2 | Correct | 4679 ms | 608676 KB | Output is correct |
3 | Correct | 319 ms | 116156 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 347 ms | 116132 KB | Output is correct |
2 | Execution timed out | 5067 ms | 606900 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 69 ms | 78636 KB | Output is correct |
2 | Execution timed out | 5100 ms | 599400 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |