# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
248358 | 2020-07-12T09:44:21 Z | NONAME | Sirni (COCI17_sirni) | C++14 | 4379 ms | 681172 KB |
#include <bits/stdc++.h> #define dbg(x) cerr << #x << " = " << x << "\n" #define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie() using namespace std; using ll = long long; const int oo = int(1e7) + 1; const int N = int(1e5) + 10; int n, a[N], pr[N]; vector <pair <int, int> > g[oo]; int f(int x) { return (x == pr[x]) ? x : pr[x] = f(pr[x]); } int main() { //fast_io; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]), pr[i] = i; sort(a, a + n); for (int i = 0; i < n - 1; ++i) { if (a[i] == a[i + 1]) g[0].push_back(make_pair(i, i + 1)); for (int j = a[i]; j <= oo; j += a[i]) { int p = lower_bound(a, a + n, (j == a[i] ? j + 1 : j)) - a; if (p == n) break; while (j <= a[p]) j += a[i]; j -= a[i]; g[a[p] - j].push_back(make_pair(i, p)); } } ll ans = 0; int kol = 0; for (int i = 0; i < oo; ++i) for (auto j : g[i]) { int x = f(j.first); int y = f(j.second); if (x == y) continue; ans += i; ++kol; if (kol == n - 1) return void(printf("%I64d\n", ans)), 0; pr[y] = x; } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 120 ms | 235256 KB | Output is correct |
2 | Correct | 139 ms | 238072 KB | Output is correct |
3 | Correct | 131 ms | 235384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 120 ms | 235384 KB | Output is correct |
2 | Correct | 157 ms | 236280 KB | Output is correct |
3 | Correct | 122 ms | 235384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 129 ms | 235296 KB | Output is correct |
2 | Correct | 127 ms | 235296 KB | Output is correct |
3 | Correct | 125 ms | 235384 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 269 ms | 245420 KB | Output is correct |
2 | Correct | 687 ms | 282504 KB | Output is correct |
3 | Correct | 343 ms | 255840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 137 ms | 236792 KB | Output is correct |
2 | Correct | 2091 ms | 504636 KB | Output is correct |
3 | Correct | 293 ms | 247476 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 491 ms | 260364 KB | Output is correct |
2 | Correct | 1002 ms | 313036 KB | Output is correct |
3 | Correct | 298 ms | 250180 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 171 ms | 239452 KB | Output is correct |
2 | Correct | 843 ms | 304028 KB | Output is correct |
3 | Correct | 320 ms | 253920 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 282 ms | 247912 KB | Output is correct |
2 | Correct | 2886 ms | 533340 KB | Output is correct |
3 | Correct | 317 ms | 250604 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 275 ms | 247884 KB | Output is correct |
2 | Correct | 4200 ms | 648848 KB | Output is correct |
3 | Correct | 375 ms | 257132 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 152 ms | 237560 KB | Output is correct |
2 | Correct | 4379 ms | 681172 KB | Output is correct |
3 | Correct | 358 ms | 255956 KB | Output is correct |