# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1004132 |
2024-06-21T05:39:54 Z |
fuad27 |
Sirni (COCI17_sirni) |
C++17 |
|
71 ms |
17776 KB |
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
int suff[N];
int pos[N];
struct DSU {
vector<int> e;
DSU(int n) {
e=vector<int>(n,-1);
}
int get(int a) {
if(e[a] < 0)return a;
return e[a]=get(e[a]);
}
int unite(int a, int b) {
a=get(a),b=get(b);
if(a==b)return 0;
if(-e[a] > -e[b])swap(a,b);
e[b]+=e[a];
e[a] = b;
return 1;
}
};
int main () {
memset(suff, -1, sizeof suff);
int n;
cin >> n;
set<int> s;
for(int i = 0;i<n;i++) {
int v;
cin >> v;
s.insert(v);
}
vector<int> v(s.begin(), s.end());
{
int cnt=0;
for(int i:v) {
suff[i] =i;
pos[i] = cnt++;
}
}
for(int i = N-2;i>=0;i--) {
if(suff[i] == -1)suff[i] = suff[i+1];
}
vector<pair<int,int>> e[N];
for(int i:v) {
for(int j = i;j<N;j+=i) {
if(suff[j] == j) {
e[0].push_back({j, i});
if(suff[j+1]!=-1) {
e[suff[j+1]-j].push_back({suff[j+1], i});
}
}
else if(suff[j]!=-1){
e[suff[j]-j].push_back({suff[j], i});
}
}
}
long long sum=0;
DSU d(n);
for(int i = 0;i<N;i++) {
for(auto [u, x]:e[i]) {
sum+=i*d.unite(pos[u], pos[x]);
}
}
cout << sum << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
6236 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3164 KB |
Output is correct |
2 |
Runtime error |
4 ms |
5980 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
6032 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
58 ms |
17200 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
8356 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
56 ms |
17236 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
25 ms |
10680 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
59 ms |
17724 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
71 ms |
17776 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
14 ms |
8876 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |