# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
984239 |
2024-05-16T11:58:10 Z |
farica |
Sirni (COCI17_sirni) |
C++14 |
|
1055 ms |
133036 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MAX_N = 10000001, MAX_SIZ = 100000;
int T[MAX_N], parent[MAX_SIZ], siz[MAX_SIZ];
int find_parent(int x) {
if(parent[x] == x) return x;
return parent[x] = find_parent(parent[x]);
}
void unite(int a, int b) {
int x = find_parent(a), y = find_parent(b);
if(x==y) return;
if(siz[x] < siz[y]) swap(x,y);
siz[x] += siz[y];
parent[y] = x;
}
void solve() {
int n;
cin >> n;
int a[n];
for(int i=0; i<n; ++i) {
cin >> a[i];
parent[i] = i;
siz[i] = 1;
}
sort(a, a+n);
for(int i=0; i<n; ++i) T[a[i]] = i + 1;
for(int i=a[n-1]; i>0; --i) {
if(T[i]) continue;
T[i] = T[i+1];
}
int ans = 0;
priority_queue<pair<int,pair<int,int>>>pq;
for(int i=0; i<n-1; ++i) {
for(int j=a[i]; j<=a[n-1]; j+=a[i]) {
int x, p;
if(j==a[i]) x = a[T[a[i]+1]-1], p = T[a[i]+1];
else x = a[T[j]-1], p = T[j];
if(x > j+a[i]) continue;
pq.push({-1 * x%a[i], {p-1, i}});
}
}
while(!pq.empty()) {
int w = -pq.top().first, x = pq.top().second.first, y = pq.top().second.second;
pq.pop();
if(find_parent(x) == find_parent(y)) continue;
unite(x, y);
ans += w;
}
cout << ans << endl;
}
signed main()
{
int t=1;
while(t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
80212 KB |
Output is correct |
2 |
Incorrect |
117 ms |
87968 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
80336 KB |
Output is correct |
2 |
Incorrect |
38 ms |
79916 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
347 ms |
62568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
43 ms |
18376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1055 ms |
111476 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
102 ms |
19256 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
483 ms |
131764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
480 ms |
133036 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
85 ms |
87344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |