Submission #1085109

# Submission time Handle Problem Language Result Execution time Memory
1085109 2024-09-07T14:12:31 Z fryingduc Sirni (COCI17_sirni) C++17
0 / 140
185 ms 239768 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef duc_debug
#include "bits/debug.h"
#else 
#define debug(...)     
#endif

const int maxn = 1e5 + 5;
const int N = 1e7 + 7;
int n, a[maxn];
vector<int> value[N];

int lab[maxn];

int find(int u) {
  return lab[u] < 0 ? u : lab[u] = find(lab[u]);
}
bool is_joined(int u, int v) {
  u = find(u), v = find(v);
  if(u == v) return 1;
  if(lab[u] > lab[v]) swap(u, v);
  lab[u] += lab[v];
  lab[v] = u;
  return 0;
}
void solve() {
  cin >> n;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
    lab[i] = -1;
    value[a[i]].push_back(i);
  }
  sort(a + 1, a + n + 1);
  int rem = 0;
  long long ans = 0;
  while(1) {
    for(int i = 1; i <= n; ++i) {
      for(int j = a[i] + rem; j <= a[n]; j += a[i]) {
        if(value[j].empty()) continue;
        for(auto pos:value[j]) {
          if(!is_joined(i, pos)) {
            ans += rem;
          }
        }
      }
    }
    bool flag = 1;
    for(int i = 2; i <= n; ++i) {
      if(find(i) != find(1)) {
        flag = 0;
        break;
      }
    }
    if(flag) {
      cout << ans;
      return;
    }
    ++rem;
  }
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  solve();

  return 0;
}

# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 235092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 235088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 123 ms 235240 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 163 ms 239676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 101 ms 235816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 160 ms 239444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 107 ms 236884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 146 ms 239692 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 185 ms 239768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 154 ms 236112 KB Output isn't correct
2 Halted 0 ms 0 KB -