Submission #891798

# Submission time Handle Problem Language Result Execution time Memory
891798 2023-12-24T04:42:19 Z cuman Sirni (COCI17_sirni) C++14
0 / 140
495 ms 126384 KB
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(),v.end()
using i64 = long long;
#define rep(i,l,r) for (int i = (l); i <= (r); i++)
 
struct DSU {
    vector<int> e;
    void initSz(int n) {
        e = vector<int>(n, -1);
    }
    int fr(int x) { return e[x] < 0 ? x : e[x] = fr(e[x]); }
    bool unite(int x, int y) {
        x = fr(x), y = fr(y);
        if (x==y) return false;
        if (e[x] > e[y]) swap(x,y);
        e[x] += e[y];
        e[y] = x;
        return true;
    }
};

signed main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int& i : A) cin >> i;

    sort(all(A));
    A.erase(unique(all(A)), A.end());
    N = A.size();

    int Largest = A.back();

    vector<int> lb(Largest+1);
    for (int i = 0; i <= Largest; i++) {
        lb[i] = lower_bound(all(A), i) - A.begin();
    }

    vector<array<int,3>> edges;
    for (int i = 0; i < N; i++) {
        for (int at = A[i]; at <= Largest; at += A[i]) {
            int j = lb[at];
            if (j == i) j++;
            if (j < N) {
                edges.push_back({A[j] % A[i], i, j});
            }
        }
    }

    sort(all(edges));
    DSU dsu;
    long long res = 0;
    for (int i = 0; i < edges.size(); i++) {
        int w = edges[i][0];
        int u = edges[i][1];
        int v = edges[i][2];
        res += w * dsu.unite(u, v);
    }

    cout << res;
    return 0;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:53:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for (int i = 0; i < edges.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 126 ms 80172 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 856 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 114 ms 80248 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 235 ms 36344 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 46 ms 14784 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 445 ms 67492 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 71 ms 11464 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 451 ms 112768 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 495 ms 126384 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 190 ms 84552 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -