Submission #701015

# Submission time Handle Problem Language Result Execution time Memory
701015 2023-02-19T17:51:56 Z amin Sirni (COCI17_sirni) C++14
112 / 140
1084 ms 786432 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[20000002];
ll sz[20000002],vis[20000002];
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(ll x,ll y,ll cost)
{
    //cout<<x<<' '<<y<<' '<<cost<<endl;
    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()
{
   ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        p[a[i]]=a[i];
        sz[a[i]]=1;
        nex[a[i]]=a[i];
    }
    for(ll i=10000002;i>=0;i--)
    {
        if(nex[i]==i)
        {
            continue;
        }
        nex[i]=nex[i+1];
    }
   vector<pair<ll,ll> >v[10000002];
    for(ll i=1;i<=1e7;i++)
    {
        if(nex[i]==i&&vis[i]==0)
        {
            vis[i]=1;
            for(ll y=i;y<=1e7;y+=i)
            {
                vis[y]=1;
             //   if(nex[y]!=0)
             if(nex[y]==y)
             {
                 v[0].push_back({i,y});
             }
            if(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 Correct 238 ms 339940 KB Output is correct
2 Correct 381 ms 453116 KB Output is correct
3 Correct 276 ms 377676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 322 ms 392056 KB Output is correct
2 Correct 811 ms 689864 KB Output is correct
3 Correct 259 ms 401260 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 244 ms 341672 KB Output is correct
2 Correct 238 ms 327892 KB Output is correct
3 Correct 276 ms 354860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 449 ms 423920 KB Output is correct
2 Correct 647 ms 440804 KB Output is correct
3 Correct 584 ms 446216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 320 ms 411116 KB Output is correct
2 Correct 546 ms 426180 KB Output is correct
3 Correct 501 ms 414576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 574 ms 434492 KB Output is correct
2 Correct 565 ms 451620 KB Output is correct
3 Correct 442 ms 431916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 482 ms 399892 KB Output is correct
2 Correct 582 ms 444956 KB Output is correct
3 Correct 545 ms 443236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 480 ms 572288 KB Output is correct
2 Runtime error 691 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 452 ms 582176 KB Output is correct
2 Runtime error 699 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 317 ms 497100 KB Output is correct
2 Correct 1084 ms 754668 KB Output is correct
3 Correct 565 ms 454540 KB Output is correct