# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1016629 |
2024-07-08T09:28:24 Z |
daoda |
Sirni (COCI17_sirni) |
C++17 |
|
322 ms |
442600 KB |
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(x, a, b) for(int x=a;x < int(b); x++)
#define endl '\n'
#define TESTCASE ll t; cin >> t; for(ll T=0; T < t; T++)
using namespace std;
// using namespace __gnu_pbds;
typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef vector<short> vs;
typedef long double ld;
// template <class T>
// using Tree =
// tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll INF = ll(1e18) + 10;
const ll INIT = 7;
const ll MAX_VAL = 5000;
const ll MAX_SZ = (ll) 1e4;
const ll MAX_N = 1e5;
const ll MAX_P = 1e7;
const long double eps = 1e-4;
const ll MOD = ll(1e9) + 7;
vi rd = {0, 1, 0, -1}, cd = {1, 0, -1, 0};
ll add(ll a, ll b) {
return ((a % MOD) + (b % MOD) + 2ll * MOD) % MOD;
}
ll mult(ll a, ll b) {
return (((a % MOD) * (b % MOD)) + MOD) % MOD;
}
ll lcm(ll a, ll b) {
return (a * b) / gcd(a, b);
}
struct DSU {
vi ids, comp_sz;
DSU(int sz) {
ids.resize(sz + 1);
comp_sz.resize(sz + 1, 1);
FOR(ind, 1, sz + 1) ids[ind] = ind;
}
int get(int x) { return ((x == ids[x]) ? x : (ids[x] = get(ids[x]))); }
int f_sz(int x) { return comp_sz[get(x)]; }
bool unite(int a, int b) {
int id_sm = get(a), id_lg = get(b);
if(id_sm == id_lg) return false;
if(comp_sz[id_sm] > comp_sz[id_lg]) swap(id_sm, id_lg);
comp_sz[id_lg] += comp_sz[id_sm];
ids[id_sm] = id_lg;
return true;
}
};
DSU dsu(MAX_N + 1);
vpi edge[(MAX_P / 2) + 1];
int closest[MAX_P + 2], dist[MAX_P + 2];
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
fast
// TESTCASE {
// }
int n;
cin >> n;
int unused_id = 1;
FOR(i, 0, n) {
int num;
cin >> num;
closest[num] = unused_id;
unused_id++;
}
if(closest[1]) {
cout << 0;
return 0;
}
for(int i = MAX_P - 1, cur_dist = 1; i >= 1; i--, cur_dist++) {
if(closest[i]) cur_dist = 0;
closest[i] = closest[i + cur_dist];
dist[i] = cur_dist;
}
FOR(i, 2, MAX_P + 1) {
if(closest[i] && !dist[i]) {
if(closest[i + 1]) edge[dist[i + 1] + 1].push_back(make_pair(closest[i + 1], closest[i]));
for(int j = 2*i; j <= MAX_P; j += i) {
if(!closest[j]) break;
edge[dist[j]].push_back(make_pair(closest[j], closest[i]));
}
}
}
ll ans = 0;
FOR(i, 0, MAX_P + 1) {
for(auto [a, b] : edge[i]) {
if(dsu.unite(a, b)) ans += i;
// cout << a << " " << b << " " << i << endl;
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
233 ms |
399188 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
218 ms |
399288 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
276 ms |
399184 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
247 ms |
418176 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
215 ms |
403024 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
322 ms |
442600 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
221 ms |
405592 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
266 ms |
426088 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
276 ms |
434888 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
229 ms |
403312 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |