# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
984257 |
2024-05-16T12:11:27 Z |
farica |
Sirni (COCI17_sirni) |
C++14 |
|
434 ms |
181404 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];
if(a[i] == a[i-1]) {
--n, --i;
continue;
}
parent[i] = i;
siz[i] = 1;
}
sort(a, a+n);
memset(T, -1, sizeof T);
for(int i=0; i<n; ++i) T[a[i]] = i;
for(int i=a[n-1]; i>0; --i) {
if(T[i] != -1) continue;
T[i] = T[i+1];
}
int ans = 0;
vector<pair<int,pair<int,int>>>pq;
for(int i=0; i<n-1; ++i) {
pq.push_back({a[T[a[i]+1]]%a[i], {T[a[i]+1], i}});
for(int j=2*a[i]; j<=a[n-1]; j+=a[i]) {
int p = T[j];
pq.push_back({a[p]%a[i], {p, i}});
}
}
sort(pq.begin(), pq.end());
for(int i=0; i<pq.size(); ++i) {
int w = pq[i].first, x = pq[i].second.first, y = pq[i].second.second;
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;
}
Compilation message
sirni.cpp: In function 'void solve()':
sirni.cpp:53:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for(int i=0; i<pq.size(); ++i) {
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
80208 KB |
Output is correct |
2 |
Incorrect |
348 ms |
178808 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
80408 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
80360 KB |
Output is correct |
2 |
Incorrect |
33 ms |
80148 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
193 ms |
130400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
38 ms |
88524 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
434 ms |
181404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
73 ms |
94704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
243 ms |
131288 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
292 ms |
130508 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
60 ms |
88516 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |