Submission #701010

# Submission time Handle Problem Language Result Execution time Memory
701010 2023-02-19T17:36:14 Z amin Sirni (COCI17_sirni) C++14
0 / 140
564 ms 576984 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[10000002];
ll sz[10000002],vis[10000002];
ll p[20000000];
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=10000000;i>=0;i--)
    {
        if(nex[i]==i)
        {
            continue;
        }
        nex[i]=nex[i+1];
    }
   vector<pair<ll,ll> >v[10000000];
    for(int i=1;i<=1e7;i++)
    {
        if(nex[i]==i&&vis[i]==0)
        {
            vis[i]=1;
            for(int y=i;y<=1e7;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<1e7;i++)
    {
        for(auto y:v[i])
        {
            un(y.first,y.second,i);
        }
    }
    cout<<ans;

}




# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 339840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 318 ms 391956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 236 ms 341824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 464 ms 418264 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 284 ms 410656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 497 ms 424132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 427 ms 397612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 445 ms 569300 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 564 ms 576984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 325 ms 496772 KB Output isn't correct
2 Halted 0 ms 0 KB -