# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
582426 |
2022-06-23T18:22:33 Z |
Ronin13 |
Sirni (COCI17_sirni) |
C++14 |
|
3110 ms |
616620 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];
vector <vector <pii> > edges(PMAX);
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;
for(int to : st){
int x = last[to + 1];
if(x < 2 * to && x < 1e7 + 1)
edges[x - to].pb({p[x], ind});
for(int i = 2 * to; i <= 1e7; i += to){
x = last[i];
if(x > 1e7) break;
if(x > 1e7 || x >= i + to) continue;
edges[x - i].pb({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 < PMAX; i++){
for(auto to : edges[i]){
int x = to.f, y = to.s;
//cout << find_set(x) << ' ' << find_set(y) << "\n";
if(find_set(x) == find_set(y)) continue;
sum += (ll)i;
union_sets(x, y);
}
}
cout << sum;
return 0;
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:88:9: warning: unused variable 'cnt' [-Wunused-variable]
88 | int cnt = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
278136 KB |
Output is correct |
2 |
Correct |
177 ms |
278760 KB |
Output is correct |
3 |
Correct |
160 ms |
278484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
159 ms |
274500 KB |
Output is correct |
2 |
Correct |
335 ms |
275476 KB |
Output is correct |
3 |
Correct |
164 ms |
278476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
278432 KB |
Output is correct |
2 |
Correct |
154 ms |
276872 KB |
Output is correct |
3 |
Correct |
168 ms |
278472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
258 ms |
293240 KB |
Output is correct |
2 |
Correct |
362 ms |
320056 KB |
Output is correct |
3 |
Correct |
283 ms |
297652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
280640 KB |
Output is correct |
2 |
Correct |
295 ms |
300152 KB |
Output is correct |
3 |
Correct |
227 ms |
290760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
301 ms |
304936 KB |
Output is correct |
2 |
Correct |
403 ms |
334624 KB |
Output is correct |
3 |
Correct |
250 ms |
296840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
280484 KB |
Output is correct |
2 |
Correct |
366 ms |
328544 KB |
Output is correct |
3 |
Correct |
254 ms |
296112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
323 ms |
331516 KB |
Output is correct |
2 |
Correct |
1328 ms |
527972 KB |
Output is correct |
3 |
Correct |
357 ms |
333892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
327 ms |
331444 KB |
Output is correct |
2 |
Correct |
2650 ms |
616620 KB |
Output is correct |
3 |
Correct |
405 ms |
337588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
198 ms |
311824 KB |
Output is correct |
2 |
Correct |
3110 ms |
604444 KB |
Output is correct |
3 |
Correct |
255 ms |
298024 KB |
Output is correct |