# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
888585 |
2023-12-17T22:10:36 Z |
asdasdqwer |
Sirni (COCI17_sirni) |
C++14 |
|
835 ms |
133624 KB |
// #pragma GCC optimze("O3")
// #pragma GCC target("avx,avx2,sse4")
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
struct DSU {
vector<int> p, r;
DSU(int n) {
p.assign(n,0);
r.assign(n,0);
for (int i=0;i<n;i++)p[i]=i;
}
int get(int i) {
if (i != p[i]) p[i]=get(p[i]);
return p[i];
}
bool unite(int a,int b) {
a=get(a);
b=get(b);
if (a==b)return false;
if (r[a]<r[b])swap(a,b);
p[b]=a;
if (r[a]==r[b])r[a]++;
return true;
}
};
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
vector<int> a(n);
for (int &x:a)cin>>x;
sort(a.begin(),a.end());
vector<int> b;
for (int x:a) {
if (b.size()==0||b.back()!=x)b.push_back(x);
}
vector<int> clos(b.back()+1,-1);
for (int x:b) {
clos[x]=x;
}
for (int i=clos.size()-2;i>=0;i--) {
if (clos[i] == -1) {
clos[i]=clos[i+1];
}
}
typedef array<int,3> pii;
vector<pii> edg;
for (int x:b) {
vector<pii> tmp;
for (int j=2*x;j<=b.back();j+=x) {
if (clos[j] != -1) {
if (!tmp.size()) {
tmp.push_back({clos[j] % x, clos[j], x});
}
else if (tmp.back()[1] != clos[j]) {
tmp.push_back({clos[j] % x, clos[j], x});
}
}
}
if (tmp.size() == 0 || tmp.back()[1] != clos[b.back()]) {
tmp.push_back({clos[b.back()] % x, clos[b.back()], x});
}
for (auto x:tmp) edg.push_back(x);
}
sort(edg.begin(),edg.end());
map<int,int> mp;
for (int i=0;i<b.size();i++) {
mp[b[i]]=i;
}
for (auto &x:edg) {
x[1]=mp[x[1]];
x[2]=mp[x[2]];
}
DSU d(b.size());
int cost=0;
for (auto x:edg) {
if (d.unite(x[1], x[2])) {
// cout<<b[x[1]]<<" "<<b[x[2]]<<"\n";
cost+=x[0];
}
}
cout<<cost<<"\n";
}
Compilation message
sirni.cpp: In function 'int main()':
sirni.cpp:82:19: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
82 | for (int i=0;i<b.size();i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
78932 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
34 ms |
78940 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
386 ms |
40852 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
51 ms |
15832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
835 ms |
109784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
116 ms |
16968 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
533 ms |
132428 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
522 ms |
133624 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
86440 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |