# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
582275 |
2022-06-23T15:20:17 Z |
Ronin13 |
Sirni (COCI17_sirni) |
C++14 |
|
5000 ms |
608580 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(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 |
35 ms |
43272 KB |
Output is correct |
2 |
Correct |
93 ms |
45644 KB |
Output is correct |
3 |
Correct |
30 ms |
43672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
35 ms |
39812 KB |
Output is correct |
2 |
Correct |
253 ms |
41116 KB |
Output is correct |
3 |
Correct |
35 ms |
43760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
43604 KB |
Output is correct |
2 |
Correct |
28 ms |
41992 KB |
Output is correct |
3 |
Correct |
29 ms |
43676 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
227 ms |
64692 KB |
Output is correct |
2 |
Correct |
788 ms |
113360 KB |
Output is correct |
3 |
Correct |
311 ms |
79960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
48360 KB |
Output is correct |
2 |
Correct |
437 ms |
108736 KB |
Output is correct |
3 |
Correct |
234 ms |
62116 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
472 ms |
113572 KB |
Output is correct |
2 |
Correct |
977 ms |
179096 KB |
Output is correct |
3 |
Correct |
285 ms |
80752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
50216 KB |
Output is correct |
2 |
Correct |
917 ms |
178308 KB |
Output is correct |
3 |
Correct |
310 ms |
80300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
304 ms |
116352 KB |
Output is correct |
2 |
Correct |
4665 ms |
608580 KB |
Output is correct |
3 |
Correct |
325 ms |
116280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
295 ms |
116128 KB |
Output is correct |
2 |
Execution timed out |
5089 ms |
606900 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
78652 KB |
Output is correct |
2 |
Execution timed out |
5088 ms |
599428 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |