Submission #887141

# Submission time Handle Problem Language Result Execution time Memory
887141 2023-12-13T21:25:18 Z Servant_of_the_Lord Sirni (COCI17_sirni) C++17
42 / 140
4784 ms 786432 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,sse4")
#define ll long long

using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll x,y,z,a,b,c;
    cin>>x;
    set<ll>s;
    map<ll,ll>m;
    for(ll i=0;i<x;i++)
    {
        cin>>y;
        s.insert(y);
        m[y]=i;
    }
    array<vector<short>,10'000'000>v;
    for(ll i:s)
    {
        c=m[i];
        if(v[i-1].empty())
        {
            for(ll j=i-1;j<10'000'000;j+=i)
            {
                v[j].push_back(c);
            }
        }
    }
    vector<ll>w(x,-1);
    function<ll(ll)>g=[&](ll a){return w[a]<0?a:w[a]=g(w[a]);};
    function<bool(ll,ll)>u=[&](ll a,ll b)
    {
        a=g(m[a]),b=g(b);
        if(a==b)return false;
        if(w[a]>w[b])swap(a,b);
        w[a]+=w[b];
        w[b]=a;
        return true;
    };
    a=0;
    bitset<10'000'000>t;
    for(ll i=0;i<10'000'000;i++)
    {
        vector<ll>e;
        for(ll j:s)
        {
            for(short &k:v[j-i-1])
            {
                if(u(j,k))
                {
                    a+=i;
                }
            }
            if(j-i-1==0||t[j-i-1])e.push_back(j);
            t[j-i-1]=1;
        }
        for(ll j:e)s.erase(j);
        if(s.empty())break;
    }
    cout<<a<<'\n';
}

Compilation message

sirni.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:13:12: warning: unused variable 'z' [-Wunused-variable]
   13 |     ll x,y,z,a,b,c;
      |            ^
sirni.cpp:13:16: warning: unused variable 'b' [-Wunused-variable]
   13 |     ll x,y,z,a,b,c;
      |                ^
# Verdict Execution time Memory Grader output
1 Correct 677 ms 236884 KB Output is correct
2 Correct 1509 ms 295412 KB Output is correct
3 Correct 723 ms 237308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 841 ms 364432 KB Output is correct
2 Correct 3271 ms 513604 KB Output is correct
3 Correct 688 ms 238636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 684 ms 236884 KB Output is correct
2 Correct 420 ms 236880 KB Output is correct
3 Correct 664 ms 237140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 2368 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 522 ms 284372 KB Output is correct
2 Runtime error 2302 ms 770928 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4306 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3955 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 589 ms 576244 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 605 ms 600360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 991 ms 244544 KB Output is correct
2 Runtime error 4784 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -