# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
954470 |
2024-03-28T02:50:11 Z |
HuyAT |
Sirni (COCI17_sirni) |
C++17 |
|
2881 ms |
786432 KB |
#include<bits/stdc++.h>
const int MaxV = 1e7 + 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){
nxt[i] = t;
if(!mark[i]){
continue;
}
for(int j = i;j <= MaxV;j += i){
if(mark[j] && i != j){
edge[0].emplace_back(i,j);
continue;
}
if(nxt[j] != -1){
edge[nxt[j] - j].emplace_back(i,nxt[j]);
}
}
t = i;
}
}
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 |
Correct |
238 ms |
316748 KB |
Output is correct |
2 |
Correct |
713 ms |
348004 KB |
Output is correct |
3 |
Correct |
162 ms |
317288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
313652 KB |
Output is correct |
2 |
Runtime error |
2881 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
156 ms |
317016 KB |
Output is correct |
2 |
Correct |
172 ms |
314716 KB |
Output is correct |
3 |
Correct |
144 ms |
316972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
299 ms |
324660 KB |
Output is correct |
2 |
Correct |
697 ms |
355788 KB |
Output is correct |
3 |
Correct |
402 ms |
335364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
170 ms |
316544 KB |
Output is correct |
2 |
Correct |
568 ms |
338516 KB |
Output is correct |
3 |
Correct |
378 ms |
324232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
524 ms |
336536 KB |
Output is correct |
2 |
Correct |
828 ms |
367444 KB |
Output is correct |
3 |
Correct |
349 ms |
332912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
368 ms |
317420 KB |
Output is correct |
2 |
Correct |
976 ms |
374736 KB |
Output is correct |
3 |
Correct |
367 ms |
334464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
233 ms |
337428 KB |
Output is correct |
2 |
Correct |
1584 ms |
682340 KB |
Output is correct |
3 |
Correct |
262 ms |
340244 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
225 ms |
341712 KB |
Output is correct |
2 |
Runtime error |
1719 ms |
786432 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
148 ms |
325708 KB |
Output is correct |
2 |
Correct |
1960 ms |
705924 KB |
Output is correct |
3 |
Correct |
371 ms |
335708 KB |
Output is correct |