Submission #1042609

# Submission time Handle Problem Language Result Execution time Memory
1042609 2024-08-03T08:29:36 Z Abito Sirni (COCI17_sirni) C++17
0 / 140
2604 ms 523112 KB
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define ep insert
#define endl '\n'
#define elif else if
#define pow pwr
#define sqrt sqrtt
//#define int long long
#define ll long long
#define y1 YONE
typedef unsigned long long ull;
using namespace std;
const int N=1e7+5;
int a[N],n,par[N],sz[N];
int getpar(int x){
    if (x==par[x]) return x;
    return par[x]=getpar(par[x]);
}
void link(int x,int y){
    x=getpar(x);
    y=getpar(y);
    if (x==y) return;
    if (sz[x]>sz[y]) swap(x,y);
    sz[y]+=sz[x];
    par[x]=y;
    return;
}
vector<int> d[N];
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i],par[i]=i,sz[i]=1;
    sort(a+1,a+1+n);
    int mx=0,k=0,ans=0;
    vector<vector<int>> v;
    for (int i=1;i<=n;i++){
        while (k<a[i]){
            k++;
            if (d[k].size()) mx=k;
        }
        for (auto u:d[mx]) v.pb({a[i]%a[u],i,u});
        for (int j=a[i];j<N;j+=a[i]) d[j].pb(i);
    }
    sort(v.begin(),v.end());
    for (auto u:v){
        int x=getpar(u[1]),y=getpar(u[2]);
        if (x==y) continue;
        link(x,y);
        ans+=u[0];
    }
    cout<<ans<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 80 ms 235352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 710 ms 370032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 89 ms 235352 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1156 ms 409112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 283080 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2604 ms 523112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1669 ms 475504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 279 ms 279816 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 292100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 118 ms 242512 KB Output isn't correct
2 Halted 0 ms 0 KB -