Submission #887138

# Submission time Handle Problem Language Result Execution time Memory
887138 2023-12-13T21:06:52 Z Servant_of_the_Lord Sirni (COCI17_sirni) C++17
98 / 140
5000 ms 611964 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#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;
    }
    vector<vector<ll>>v(10'000'000);
    for(ll i:s)
    {
        if(v[i-1].empty())
        {
            for(ll j=i-1;j<10'000'000;j+=i)
            {
                v[j].push_back(i);
            }
        }
    }
    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(m[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(ll 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;
      |                ^
sirni.cpp:13:18: warning: unused variable 'c' [-Wunused-variable]
   13 |     ll x,y,z,a,b,c;
      |                  ^
# Verdict Execution time Memory Grader output
1 Correct 277 ms 236628 KB Output is correct
2 Correct 1159 ms 299604 KB Output is correct
3 Correct 274 ms 237948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 653 ms 372352 KB Output is correct
2 Correct 3644 ms 583788 KB Output is correct
3 Correct 292 ms 238596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 270 ms 236636 KB Output is correct
2 Correct 133 ms 236628 KB Output is correct
3 Correct 269 ms 236808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1635 ms 408340 KB Output is correct
2 Correct 2619 ms 549756 KB Output is correct
3 Correct 2715 ms 595500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 352 ms 285008 KB Output is correct
2 Correct 2340 ms 428628 KB Output is correct
3 Correct 2228 ms 507596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2515 ms 476060 KB Output is correct
2 Correct 2624 ms 611964 KB Output is correct
3 Correct 1755 ms 503652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1576 ms 458852 KB Output is correct
2 Correct 3013 ms 609688 KB Output is correct
3 Correct 2394 ms 572752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1583 ms 285592 KB Output is correct
2 Execution timed out 5083 ms 558900 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2051 ms 297292 KB Output is correct
2 Execution timed out 5066 ms 602656 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 467 ms 244892 KB Output is correct
2 Execution timed out 5106 ms 504596 KB Time limit exceeded
3 Halted 0 ms 0 KB -