Submission #701009

# Submission time Handle Problem Language Result Execution time Memory
701009 2023-02-19T17:35:22 Z amin Sirni (COCI17_sirni) C++14
0 / 140
5 ms 6768 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define rep(i,a,b) for(i=a;i<b;i++)
ll nex[100002];
ll sz[100002],vis[100002];
ll p[200000];
ll ans=0;
int par(int x)
{
    if(p[x]==x)
    return x;
    p[x]=par(p[x]);
    return p[x];
}
void un(int x,int y,ll cost)
{
    x=par(x);
    y=par(y);
    if(x==y)
    {
        return ;
    }
    ans+=cost;
if(sz[x]<sz[y])
{
    swap(x,y);
}
sz[x]+=sz[y];
sz[y]=0;
p[y]=x;
}

int main()
{
    int n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        p[a[i]]=a[i];
        sz[a[i]]=1;
        nex[a[i]]=a[i];
    }
    for(int i=100000;i>=0;i--)
    {
        if(nex[i]==i)
        {
            continue;
        }
        nex[i]=nex[i+1];
    }
   vector<pair<ll,ll> >v[100000];
    for(int i=1;i<=1e5;i++)
    {
        if(nex[i]==i&&vis[i]==0)
        {
            vis[i]=1;
            for(int y=i;y<=1e5;y+=i)
            {
                vis[y]=1;
                if(nex[y+1]!=0&&vis[nex[y+1]]==0)
                v[nex[y+1]%i].push_back({i,nex[y+1]});
            }
        }
    }
    for(ll i=0;i<1e5;i++)
    {
        for(auto y:v[i])
        {
            un(y.first,y.second,i);
        }
    }
    cout<<ans;

}




# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 5076 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 5184 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 6740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 5332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 6740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5716 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 6768 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 5 ms 6740 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 5392 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -