# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954593 |
2024-03-28T07:57:54 Z |
HuyAT |
Sirni (COCI17_sirni) |
C++17 |
|
5 ms |
5368 KB |
#include<bits/stdc++.h>
const int MaxV = 1e5 + 10;
struct DSU{
std::vector<int> lab;
DSU(int n) : lab(n + 1,-1){
}
int findSet(int i){
return (lab[i] < 0 ? i : lab[i] = findSet(lab[i]));
}
bool sameSet(int x,int y){
return (findSet(x) == findSet(y));
}
void merg(int x,int y){
x = findSet(x);
y = findSet(y);
if(x == y){
return;
}
if(-lab[x] > -lab[y]){
std::swap(x,y);
}
lab[y] += lab[x];
lab[x] = y;
}
};
bool mark[MaxV + 1];
int n,nxt[MaxV + 1];
std::vector<std::pair<int,int>> edge[MaxV + 1];
void readData(){
std::cin >> n;
for(int i = 1;i <= n;++i){
int v;
std::cin >> v;
mark[v] = true;
}
}
void precompute(){
int t = -1;
for(int i = MaxV;i >= 1;--i){
if(!mark[i]){
nxt[i] = t;
continue;
}
t = i;
nxt[i] = i;
for(int j = i * 2;j <= MaxV;j += i){
if(mark[j] && i != j){
edge[0].emplace_back(i,j);
continue;
}
if(nxt[j] != -1){
j = (nxt[j] / i) * i;
edge[nxt[j] - j].emplace_back(i,nxt[j]);
}else{
break;
}
}
}
}
long long solve(){
long long ans = 0;
DSU graph(MaxV);
for(int i = 0;i <= MaxV;++i){
for(std::pair<int,int> e : edge[i]){
if(!graph.sameSet(e.first,e.second)){
ans += i;
graph.merg(e.first,e.second);
}
}
}
return ans;
}
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);std::cout.tie(nullptr);
readData();
precompute();
std::cout << solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5368 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
4 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5208 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
5 ms |
5132 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5344 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
5212 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |