# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
978922 |
2024-05-10T03:17:46 Z |
Br3ad |
Sirni (COCI17_sirni) |
C++17 |
|
455 ms |
130352 KB |
#include <iostream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define PF push_front
#define PB push_back
#define MP make_pair
#define max(a, b) ((a > b)? a : b)
#define min(a, b) ((a < b)? a : b)
#define max3(a, b, c) max(max(a, b), c)
#define min3(a, b, c) min(min(a, b), c)
const int N = 1e5 + 5;
const int P = 1e7 + 5;
const int M = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const ll int INF = 1e18;
struct DSU {
vector<int> parent;
DSU(int n){
parent = vector<int>(n);
iota(parent.begin(), parent.end(), 0);
}
int find_parent(int p){
return (parent[p] == p)? p : parent[p] = find_parent(parent[p]);
}
bool merge(int a, int b){
a = find_parent(a);
b = find_parent(b);
parent[a] = b;
return (a != b);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
// ifstream cin();
// ofstream cout();
int n, p[N];
cin >> n;
for(int i = 0; i < n; i++){
cin >> p[i];
}
sort(p, p+n);
vector<pair<int, int>> nearest(P, MP(0, 0));
nearest[P-1] = {-1, -1};
for(int i = 0; i < n; i++) nearest[p[i]] = {p[i], i};
for(int i = P-2; i >= 0; i--){
if(nearest[i].f == 0) nearest[i] = nearest[i+1];
}
vector<pair<int, pair<int, int>>> edge;
for(int i = 0; i < n; i++){
if(nearest[p[i]+1].f == -1) break;
edge.PB(MP(nearest[p[i]+1].f%p[i], MP(i, nearest[p[i]+1].s)));
for(int cur = p[i]*2; cur < P; cur += p[i]){
if(nearest[cur].f == -1) break;
edge.PB(MP(nearest[cur].f%p[i], MP(i, nearest[cur].s)));
}
}
sort(edge.begin(), edge.end());
DSU dsu(n);
int ans = 0;
for(auto [w, p] : edge){
if(dsu.merge(p.f, p.s)){
ans += w;
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
79200 KB |
Output is correct |
2 |
Incorrect |
363 ms |
130352 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
39 ms |
79184 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
79188 KB |
Output is correct |
2 |
Incorrect |
38 ms |
79188 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
211 ms |
104484 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
67 ms |
82372 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
455 ms |
129656 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
94 ms |
85800 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
247 ms |
105404 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
286 ms |
104832 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
82348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |