Submission #470840

# Submission time Handle Problem Language Result Execution time Memory
470840 2021-09-06T00:30:07 Z SirCovidThe19th Sirni (COCI17_sirni) C++17
0 / 140
353 ms 293036 KB
#include <bits/stdc++.h>
using namespace std; 

const int mN = 1e5 + 5, mP = 1e7 + 5;

int n, mx, ub[mP], par[mP], sz[mP]; long long ans; vector<int> A; vector<pair<int, int>> edg[mP];

int get(int i){
    return (i == par[i]) ? i : par[i] = get(par[i]);
}
void merge(int a, int b, int w){
    a = get(a); b = get(b); if (a == b) return;
    if (a > b) swap(a, b);
    par[a] = b; sz[b] += sz[a]; ans += w;
}

int main(){
    cin >> n; A.resize(n);
    for (int &i : A) cin >> i;
    sort(A.begin(), A.end()); A.erase(unique(A.begin(), A.end()), A.end());
    n = A.size(); mx = A.back(); iota(par, par + n, 0); fill(sz, sz + n, 1);

    for (int i = 0; i < n; i++) ub[A[i]] = i;
    for (int i = mx, cur; i >= 0; i--) (ub[i]) ? cur = ub[i] : ub[i] = cur;

    for (int i = 0; i < n; i++)
        for (int x = A[i] * 2; x <= mx; x += A[i])
            edg[A[ub[x]] % x].push_back({i, ub[x]});
    for (int i = 0; i < mx; i++)
        for (auto edge : edg[i])
            merge(edge.first, edge.second, i);
    cout<<ans<<endl;
}

Compilation message

sirni.cpp: In function 'int main()':
sirni.cpp:24:70: warning: 'cur' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     for (int i = mx, cur; i >= 0; i--) (ub[i]) ? cur = ub[i] : ub[i] = cur;
      |                                                                ~~~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 174 ms 274372 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 123 ms 235272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 181 ms 274296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 249892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 164 ms 241220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 307 ms 261340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 177 ms 239776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 332 ms 288712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 353 ms 293036 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 195 ms 276624 KB Output isn't correct
2 Halted 0 ms 0 KB -