# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
886885 |
2023-12-13T06:20:45 Z |
beaboss |
Sirni (COCI17_sirni) |
C++14 |
|
4729 ms |
479052 KB |
// Source: https://oj.uz/problem/view/COCI17_sirni
//
#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vpii;
typedef vector<ll> vi;
#define FOR(i, a, b) for (ll i = (a); i<b; i++)
bool ckmin(ll& a, ll b){ return b < a ? a = b, true : false; }
bool ckmax(ll& a, ll b){ return b > a ? a = b, true : false; }
set<ll> uni;
const ll P = 1e7 + 10;
vector<pair<ll, pii> > ed;
struct DSU {
vector<ll> e;
DSU(ll N) { e = vector<ll>(N, -1); }
// get representive component (uses path compression)
ll get(ll x) { return e[x] < 0 ? x : e[x] = get(e[x]); }
bool same_set(ll a, ll b) { return get(a) == get(b); }
ll size(ll x) { return -e[get(x)]; }
bool unite(ll x, ll y) { // union by size
x = get(x), y = get(y);
if (x == y) return false;
if (e[x] > e[y]) swap(x, y);
e[x] += e[y];
e[y] = x;
return true;
}
};
DSU dsu(P);
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll n;
cin >> n;
FOR(i, 1, n + 1) {
ll k;
cin >> k;
uni.insert(k);
}
for (auto cur: uni) {
for (ll e = cur; e < P; e += cur) {
ll ub = e + cur - 1;
auto it = uni.upper_bound(ub);
if (it == uni.begin()) continue;
ll val = *prev(it, 1);
while (val >= e) {
ed.pb({val - e, {cur, val}});
ub = (e + val) / 2;
if (val == e) break;
it = uni.upper_bound(ub);
if (it == uni.begin()) break;
val = *prev(it, 1);
}
}
}
sort(ed.begin(), ed.end());
ll sz = 0;
for (auto e: ed) {
if (dsu.unite(e.s.s, e.s.f)) sz += e.f;
}
cout << sz << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
25 ms |
79712 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
108 ms |
79560 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
79704 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2210 ms |
280364 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
209 ms |
105748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4729 ms |
478400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
844 ms |
179868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2242 ms |
479052 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2294 ms |
478668 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
273 ms |
129088 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |