Submission #100745

# Submission time Handle Problem Language Result Execution time Memory
100745 2019-03-13T20:33:25 Z dalgerok Sirni (COCI17_sirni) C++17
0 / 140
5000 ms 787456 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e7 + 1;


int n, dp[N], p[N];
long long ans;
bool used[N];
vector < pair < int, int > > g[N];

int dsu_get(int v){
    return p[v] == v ? v : p[v] = dsu_get(p[v]);
}

inline void dsu_unite(int x, int y){
    x = dsu_get(x);
    y = dsu_get(y);
    if(rand() & 1){
        swap(x, y);
    }
    p[x] = y;
}

int main(){
    srand(time(nullptr));
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++){
        int x;
        cin >> x;
        p[x] = x;
        used[x] = true;
    }
    for(int i = N - 1; i >= 1; i--){
        if(used[i]){
            dp[i] = i;
        }
        else{
            dp[i] = dp[i + 1];
        }
    }
    for(int i = 1; i < N; i++){
        if(used[i]){
            for(int j = 1; i * j < N; j++){
                int x = i * j, y;
                y = dp[x];
                if(y != 0){
                    g[y % i].push_back(make_pair(i, y));
                }
                y = dp[x + 1];
                if(y != 0){
                    g[y % i].push_back(make_pair(i, y));
                }
            }
        }
    }
    for(int i = 0; i < N; i++){
        for(auto it : g[i]){
            int x = it.first,
                y = it.second;
            if(dsu_get(x) != dsu_get(y)){
                ans += i;
                dsu_unite(x, y);
            }
        }
    }
    cout << ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1794 ms 281284 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3500 ms 453228 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 303 ms 281820 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2628 ms 504288 KB Output is correct
2 Execution timed out 5150 ms 700444 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 633 ms 318288 KB Output is correct
2 Execution timed out 5056 ms 696496 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4555 ms 728596 KB Output is correct
2 Runtime error 2985 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2979 ms 628544 KB Output is correct
2 Runtime error 2257 ms 787456 KB Execution killed with signal 9 (could be triggered by violating memory limits)
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 697 ms 347704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 759 ms 358132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 389 ms 322844 KB Output isn't correct
2 Halted 0 ms 0 KB -