답안 #1070068

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1070068 2024-08-22T11:27:46 Z Plurm Sirni (COCI17_sirni) C++11
140 / 140
505 ms 42508 KB
#include <bits/stdc++.h>
using namespace std;

bitset<10000005> bs;
int par[100005];
int bck[10000005];
int fn(int x) {
    if (par[x] == -1)
        return x;
    else
        return par[x] = fn(par[x]);
}
bool un(int x, int y) {
    x = fn(x);
    y = fn(y);
    if (x == y)
        return false;
    par[x] = y;
    return true;
}
int main() {
    memset(par, -1, sizeof(par));
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> v;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        bs[x] = true;
        v.push_back(x);
    }
    sort(v.begin(), v.end());
    v.resize(unique(v.begin(), v.end()) - v.begin());
    for (int i = 0; i < v.size(); i++)
        bck[v[i]] = i;
    long long ans = 0ll;
    int join = 0;
    for (int k = 0; k <= 10000000; k++) {
        for (int i = 0; i < v.size(); i++) {
            if (!bs[v[i]])
                continue;
            for (int j = v[i] + k; j <= 10000000; j += v[i]) {
                if (bs[j] && un(bck[j], i)) {
                    ans += k;
                    join++;
                }
            }
        }
        if (join + 1 == v.size())
            break;
    }
    cout << ans << endl;
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:36:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     for (int i = 0; i < v.size(); i++)
      |                     ~~^~~~~~~~~~
sirni.cpp:41:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
sirni.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |         if (join + 1 == v.size())
      |             ~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 40796 KB Output is correct
2 Correct 113 ms 40792 KB Output is correct
3 Correct 67 ms 40796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 2908 KB Output is correct
2 Correct 69 ms 37980 KB Output is correct
3 Correct 18 ms 40796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 102 ms 40792 KB Output is correct
2 Correct 32 ms 31832 KB Output is correct
3 Correct 67 ms 40796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 136 ms 8408 KB Output is correct
2 Correct 213 ms 8412 KB Output is correct
3 Correct 53 ms 8408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 7504 KB Output is correct
2 Correct 196 ms 8268 KB Output is correct
3 Correct 166 ms 6104 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 234 ms 8408 KB Output is correct
2 Correct 143 ms 8412 KB Output is correct
3 Correct 52 ms 8408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 111 ms 5652 KB Output is correct
2 Correct 193 ms 8408 KB Output is correct
3 Correct 52 ms 8408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 180 ms 42508 KB Output is correct
2 Correct 124 ms 42456 KB Output is correct
3 Correct 159 ms 42460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 42256 KB Output is correct
2 Correct 277 ms 42204 KB Output is correct
3 Correct 36 ms 42456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 149 ms 41308 KB Output is correct
2 Correct 505 ms 42204 KB Output is correct
3 Correct 54 ms 8412 KB Output is correct