Submission #891799

# Submission time Handle Problem Language Result Execution time Memory
891799 2023-12-24T04:43:22 Z cuman Sirni (COCI17_sirni) C++14
84 / 140
1056 ms 786432 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;
    dsu.initSz(N);
    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:54: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]
   54 |     for (int i = 0; i < edges.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 85 ms 39516 KB Output is correct
2 Correct 384 ms 89936 KB Output is correct
3 Correct 86 ms 39756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 604 KB Output is correct
2 Runtime error 655 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 39560 KB Output is correct
2 Correct 78 ms 39484 KB Output is correct
3 Correct 85 ms 39764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 30216 KB Output is correct
2 Correct 751 ms 54208 KB Output is correct
3 Correct 369 ms 54452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 8656 KB Output is correct
2 Correct 367 ms 55064 KB Output is correct
3 Correct 207 ms 27840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 457 ms 56048 KB Output is correct
2 Correct 1036 ms 104352 KB Output is correct
3 Correct 367 ms 29624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 7628 KB Output is correct
2 Correct 1056 ms 103844 KB Output is correct
3 Correct 334 ms 30392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 401 ms 66684 KB Output is correct
2 Runtime error 708 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 459 ms 66428 KB Output is correct
2 Runtime error 726 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 175 ms 44260 KB Output is correct
2 Runtime error 928 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -