답안 #552555

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
552555 2022-04-23T09:46:33 Z chenwz Sirni (COCI17_sirni) C++11
112 / 140
5000 ms 396096 KB
// [COCI2016-2017#6] Sirni
#include <bits/stdc++.h>
using namespace std;
const int NN = 1e5 + 4;
#define _for(i, a, b) for (int i = (a); i < (int)(b); ++i)
int P[NN], pa[NN];
int find_set(int x) { return pa[x] == x ? x : pa[x] = find_set(pa[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;
  cin >> n;
  _for(i, 0, n) cin >> P[i], pa[i] = i;
  sort(P, P + n), n = unique(P, P + n) - P;
  long long ans = 0;
  _for(i, 0, n) for (int x = P[i], y = x; y <= P[n - 1]; y += x) {
    int k = lower_bound(P + i + 1, P + n, y) - P;
    if (k < n && P[k] / x == y / x) es.push_back({i, k, P[k] % x});
  }
  sort(es.begin(), es.end());
  for (const Edge& e : es) {
    int u = find_set(e.u), v = find_set(e.v);
    if (u != v) ans += e.w, pa[u] = v;
  }
  cout << ans << endl;
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 79 ms 3460 KB Output is correct
3 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Output is correct
2 Correct 748 ms 1224 KB Output is correct
3 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 180 ms 14192 KB Output is correct
2 Correct 605 ms 51068 KB Output is correct
3 Correct 238 ms 26524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 3684 KB Output is correct
2 Correct 323 ms 50956 KB Output is correct
3 Correct 164 ms 14128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 391 ms 51140 KB Output is correct
2 Correct 798 ms 100500 KB Output is correct
3 Correct 252 ms 26608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 61 ms 7228 KB Output is correct
2 Correct 746 ms 100256 KB Output is correct
3 Correct 223 ms 26572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 227 ms 26520 KB Output is correct
2 Correct 3890 ms 395908 KB Output is correct
3 Correct 268 ms 26564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 236 ms 26632 KB Output is correct
2 Execution timed out 5086 ms 396096 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 35 ms 3776 KB Output is correct
2 Execution timed out 5050 ms 395852 KB Time limit exceeded
3 Halted 0 ms 0 KB -