# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057745 |
2024-08-14T04:50:13 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
2467 ms |
453596 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
const int nmax = 1e7 + 1;
using ll = long long;
int n;
vector<int> v;
int root[nmax + 5];
int nxt[nmax + 5];
struct tt{
int x;
int y;
int z;
};
vector<tt> edge;
bool cmp(tt x, tt y){
return x.z < y.z;
}
int find(int u) { return (u == root[u] ? u : root[u] = find(root[u])); }
signed main(){
cin>>n;
for(int i = 1 , x ; i <= n ; ++i){
cin>>x;
v.push_back(x);
}
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
int j = 0;
for(int i = 1 ; i <= v.back() ; ++i){
while(i > v[j] ) j++;
nxt[i] = v[j];
}
for (int x : v) for (int y = x; y <= v.back(); y += x) {
int p = nxt[(y==x?y+1:y)];
if (!p) break;
if (y + x < p) y = (p - y) / x * x + y;
edge.push_back({x, p, p - y});
}
for(auto i : v) root[i] = i;
sort(edge.begin(),edge.end(),cmp);
ll ans = 0;
for (tt ee : edge) {
int u = ee.x, v = ee.y, c = ee.z;
//cout<<u<<'.'<<v<<'.'<<c<<"\n";
u = find(u), v = find(v);
if (u != v) {
root[u] = v;
ans += 1ll*c;
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
78684 KB |
Output is correct |
2 |
Correct |
29 ms |
80908 KB |
Output is correct |
3 |
Correct |
13 ms |
78876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4700 KB |
Output is correct |
2 |
Correct |
16 ms |
79364 KB |
Output is correct |
3 |
Correct |
18 ms |
78872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
78684 KB |
Output is correct |
2 |
Correct |
14 ms |
70324 KB |
Output is correct |
3 |
Correct |
12 ms |
78680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
90 ms |
23344 KB |
Output is correct |
2 |
Correct |
261 ms |
58412 KB |
Output is correct |
3 |
Correct |
120 ms |
30944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
13304 KB |
Output is correct |
2 |
Correct |
167 ms |
55116 KB |
Output is correct |
3 |
Correct |
86 ms |
19772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
168 ms |
56624 KB |
Output is correct |
2 |
Correct |
312 ms |
105508 KB |
Output is correct |
3 |
Correct |
104 ms |
30772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
30 ms |
11324 KB |
Output is correct |
2 |
Correct |
320 ms |
104008 KB |
Output is correct |
3 |
Correct |
100 ms |
30012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
150 ms |
94736 KB |
Output is correct |
2 |
Correct |
1670 ms |
435204 KB |
Output is correct |
3 |
Correct |
151 ms |
98276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
94872 KB |
Output is correct |
2 |
Correct |
2330 ms |
453596 KB |
Output is correct |
3 |
Correct |
180 ms |
103436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
80840 KB |
Output is correct |
2 |
Correct |
2467 ms |
450432 KB |
Output is correct |
3 |
Correct |
112 ms |
30784 KB |
Output is correct |