Submission #483518

# Submission time Handle Problem Language Result Execution time Memory
483518 2021-10-30T07:45:01 Z oneloveforever Sirni (COCI17_sirni) C++14
0 / 140
61 ms 6724 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define x first
#define y second
#define ii pair<int,int>
int n;
const int M=1e5+7;
struct DSU
{
    vector<int>sz,trace;
    int n;
    DSU(int _n=0)
    {
        n=_n;
        sz.assign(n+7,1);
        trace.resize(n+7);
        iota(trace.begin(),trace.end(),0);
    }
    int find_dsu(int x)
    {
        return trace[x]==x?trace[x]:find_dsu(trace[x]);
    }
    bool check(int x,int y)
    {
        int u=find_dsu(x);
        int v=find_dsu(y);
        if(u==v)return false;
        if(sz[u]>sz[v])swap(u,v);
        trace[u]=v;
        sz[v]+=sz[u];
        return true;
    }
};
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    vector<vector<ii> >edge(M+10);
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    for(int i=1;i<=n;i++)
    {
        int vt=i;
        for(int need=a[i];need<M;need+=a[i])
        {
            while(vt+1<=n&&a[vt+1]<need)vt+=1;
            edge[a[vt]%a[i]].push_back(make_pair(i,vt));
        }
    }
    DSU dsu(n);
    int ans=0;
    for(int i=0;i<M;i++)
    {
        for(ii node:edge[i])
        {
            //cout<<node.x<<" "<<node.y<<" "<<i<<endl;
            if(dsu.check(node.x,node.y))ans+=i;
        }
    }
    cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 3532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 5068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 6724 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 5408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 3968 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 4044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2892 KB Output isn't correct
2 Halted 0 ms 0 KB -