Submission #470846

# Submission time Handle Problem Language Result Execution time Memory
470846 2021-09-06T00:49:01 Z SirCovidThe19th Sirni (COCI17_sirni) C++17
112 / 140
4118 ms 786436 KB
#include <bits/stdc++.h>
using namespace std; 

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

int n, mx, ub[mP], par[mN], sz[mN]; 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 = n - 1; i >= 0; i--) (ub[i]) ? cur = ub[i] : ub[i] = cur;
    
    for (int i = 0; i < n - 1; i++)
        for (int x = A[i]; x <= mx; x += A[i])
            edg[A[ub[x + (x == A[i])]] % x].push_back({i, ub[x + (x == A[i])]});
        
    for (int i = 0; i < mx; i++)
        for (auto edge : edg[i])
            merge(edge.first, edge.second, i);
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 176 ms 274372 KB Output is correct
2 Correct 426 ms 306752 KB Output is correct
3 Correct 177 ms 274500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 235280 KB Output is correct
2 Runtime error 2535 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 178 ms 274372 KB Output is correct
2 Correct 178 ms 274208 KB Output is correct
3 Correct 175 ms 274428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 225 ms 250032 KB Output is correct
2 Correct 363 ms 279856 KB Output is correct
3 Correct 265 ms 262348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 148 ms 241220 KB Output is correct
2 Correct 307 ms 263848 KB Output is correct
3 Correct 212 ms 248480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 291 ms 262564 KB Output is correct
2 Correct 423 ms 298044 KB Output is correct
3 Correct 256 ms 259184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 162 ms 240116 KB Output is correct
2 Correct 420 ms 301396 KB Output is correct
3 Correct 268 ms 261924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 350 ms 288992 KB Output is correct
2 Correct 2270 ms 635352 KB Output is correct
3 Correct 373 ms 292284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 361 ms 293280 KB Output is correct
2 Runtime error 3533 ms 786436 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 211 ms 276860 KB Output is correct
2 Correct 4118 ms 657276 KB Output is correct
3 Correct 261 ms 261000 KB Output is correct