# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1057724 |
2024-08-14T04:19:02 Z |
vjudge1 |
Sirni (COCI17_sirni) |
C++17 |
|
4 ms |
7260 KB |
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
const int nmax = 1e7 + 1;
using ll = long long;
int n;
vector<int> g[N];
vector<int> v;
int root[nmax];
int nxt[nmax];
struct tt{
int x;
int y;
int z;
};
vector<tt> edge;
bool cmp(tt x, tt y){
return x.z < y.z;
}
inline 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);
g[x].push_back(i);
}
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;
u = find(u), v = find(v);
if (u != v) {
root[u] = v;
ans += 1ll*c;
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7260 KB |
Output is correct |
2 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5552 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5468 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |