답안 #551567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
551567 2022-04-21T04:38:26 Z chenwz Sirni (COCI17_sirni) C++14
112 / 140
5000 ms 395356 KB
#include <bits/stdc++.h>
using namespace std;
int const maxn = 1e5 + 4;
int p[maxn];
int fa[maxn];
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
struct Edge {
  int u, v, w;
  bool operator<(const Edge &e) const { return w < e.w; }
};
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  vector<Edge> es;
  int n = 0, Mx = 0;
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> p[i];
  sort(p + 1, p + n + 1);
  n = unique(p + 1, p + n + 1) - p - 1;
  Mx = p[n];
  for (int i = 1; i <= n + 1; ++i) fa[i] = i;
  long long ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x = p[i];
    for (int y = x; y <= Mx; y += x) {
      int k = lower_bound(p + i + 1, p + n + 1, y) - p;
      if (k <= n && p[k] / x == y / x) es.push_back(Edge{i, k, p[k] % p[i]});
    }
  }
  sort(es.begin(), es.end());
  for (auto e : es) {
    int u = find(e.u), v = find(e.v);
    if (u != v) ans += e.w, fa[u] = v;
  }
  cout << ans << endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 76 ms 3484 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 767 ms 1224 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 178 ms 13692 KB Output is correct
2 Correct 590 ms 50596 KB Output is correct
3 Correct 238 ms 25952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3648 KB Output is correct
2 Correct 333 ms 50380 KB Output is correct
3 Correct 168 ms 13708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 50716 KB Output is correct
2 Correct 785 ms 99948 KB Output is correct
3 Correct 231 ms 25972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 7104 KB Output is correct
2 Correct 752 ms 99916 KB Output is correct
3 Correct 219 ms 26024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 257 ms 26176 KB Output is correct
2 Correct 3876 ms 395232 KB Output is correct
3 Correct 277 ms 25764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 25828 KB Output is correct
2 Execution timed out 5039 ms 395356 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 3656 KB Output is correct
2 Execution timed out 5052 ms 395196 KB Time limit exceeded
3 Halted 0 ms 0 KB -