Submission #581801

# Submission time Handle Problem Language Result Execution time Memory
581801 2022-06-23T06:36:03 Z 3zp Sirni (COCI17_sirni) C++17
84 / 140
1454 ms 786432 KB
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[100009];
int p[100009],s[100009];
int N[10000009];
vector<pair<int,pair<int,int> > > E;
void ad(int x, int y){
    if(x != y)
    E.push_back({min(a[x]%a[y], a[y]%a[x]), {x,y}});
}
int P(int x){
    if(p[x] == x) return x;
    p[x] = P(p[x]);
    return p[x];
}
ll ans = 0;
void un(int x, int y, int z){
    x = P(x); y = P(y);
    if(x == y) return;
    if(s[x] > s[y]) swap(x, y);
    p[x] = y;
    s[x] += s[y];
    ans += z;
}
main(){
 
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        p[i] = i;
        s[i] = 1;
    }
    sort(a+1, a+n+1);
    vector<int> v;
    for(int i = 1;i  <= n; i++){
        if(a[i] == a[i-1]) continue;
        N[a[i]] = i;
        v.push_back(i);
    }
    for(int i = a[n]; i >= 0; i--){
        if(!N[i]) N[i] = N[i+1];
    }
    for(int i = 1; i < v.size(); i++){
        int x = v[i];
        for(int j = 0; j * a[x] <= a[n]; j++){
            int y = N[j*a[x]];
            if(y == x && a[y] < a[n]) y = N[a[y]+1];
            ad(x, y);
        }
    }
    sort(E.begin(), E.end());
    for(auto e: E){
        int x = e.second.first, y = e.second.second;
        un(x, y, e.first);
    }
 
    cout << ans << endl;
 
}

Compilation message

sirni.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   26 | main(){
      | ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:45:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for(int i = 1; i < v.size(); i++){
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 47 ms 39500 KB Output is correct
2 Correct 372 ms 88596 KB Output is correct
3 Correct 53 ms 39804 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 468 KB Output is correct
2 Runtime error 1026 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 45 ms 39500 KB Output is correct
2 Correct 47 ms 39392 KB Output is correct
3 Correct 47 ms 39696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 252 ms 30968 KB Output is correct
2 Correct 736 ms 55472 KB Output is correct
3 Correct 339 ms 30888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7800 KB Output is correct
2 Correct 380 ms 55128 KB Output is correct
3 Correct 234 ms 28864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 495 ms 55588 KB Output is correct
2 Correct 1020 ms 104772 KB Output is correct
3 Correct 281 ms 30936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 8128 KB Output is correct
2 Correct 1069 ms 104700 KB Output is correct
3 Correct 297 ms 30896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 332 ms 66124 KB Output is correct
2 Runtime error 1297 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 339 ms 65972 KB Output is correct
2 Runtime error 1159 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 87 ms 42908 KB Output is correct
2 Runtime error 1454 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -