# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
357883 |
2021-01-24T21:40:14 Z |
MetB |
Sirni (COCI17_sirni) |
C++14 |
|
597 ms |
558704 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const ll N = 2000001;
const ll INF = 1e18, MOD = 1e9 + 7, MOD2 = 1e6 + 3;
const int maxa = (int)1e7 + 1;
int a[N], n;
int p[N], sz[N], e[maxa + 1], u[maxa + 1];
vector<pair<int, int>> v[maxa + 1];
int f(int i, int j) {
return a[j] % a[i];
}
int find(int x) {
if (p[x] == x) return x;
return p[x] = find(p[x]);
}
bool unite(int a, int b) {
a = find(a), b = find(b);
if (a == b) return false;
if (sz[a] < sz[b]) swap(a, b);
sz[a] += sz[b];
p[b] = a;
return true;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
fill(e, e + maxa + 1, -1);
for (int i = 0; i < n; i++) {
sz[i] = 1, p[i] = i;
}
for (int i = 0; i < n; i++) {
cin >> a[i];
e[a[i]] = i;
}
sort(a, a + n);
for (int i = maxa - 1; i >= 0; i--) {
if (e[i] == -1) e[i] = e[i+1];
}
for (int i = 0; i < n; i++) {
if (e[a[i]] != i) {
v[0].push_back({i, e[a[i]]});
continue;
}
if (u[a[i]]) {
//cout << a[i] << ' ' << a[u[a[i]]] << endl;
v[0].push_back({u[a[i]], i});
continue;
}
if (e[a[i] + 1] != -1) v[f(i, e[a[i] + 1])].push_back({i, e[a[i] + 1]});
for (int k = 2 * a[i]; k < maxa; k += a[i]) {
u[k] = i;
if (e[k] != -1 && a[e[k]] <= k + a[i]) {
v[a[e[k]] - k].push_back({i, e[k]});
}
}
}
ll ans = 0;
for (int i = 0; i <= maxa; i++) {
for (auto& x : v[i]) {
if (unite(x.first, x.second)) {
ans += i;
//cout << a[x.first] << ' ' << a[x.second] << ' ' << f(x.first, x.second) << endl;
}
}
}
cout << ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
229 ms |
274412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
554 ms |
555628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
571 ms |
555756 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
578 ms |
558704 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
557 ms |
556248 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
583 ms |
558704 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
571 ms |
556936 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
269 ms |
276632 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
597 ms |
558572 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
561 ms |
556504 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |