Submission #887134

# Submission time Handle Problem Language Result Execution time Memory
887134 2023-12-13T21:00:58 Z Servant_of_the_Lord Sirni (COCI17_sirni) C++17
98 / 140
5000 ms 524284 KB
#include <bits/stdc++.h>
#pragma gcc optimize("Ofast")
#pragma gcc target("avx,avx2,sse4")
#define ll int

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);
    }
    cout<<a<<'\n';
}

Compilation message

sirni.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("Ofast")
      | 
sirni.cpp:3: warning: ignoring '#pragma gcc target' [-Wunknown-pragmas]
    3 | #pragma gcc target("avx,avx2,sse4")
      | 
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 335 ms 236628 KB Output is correct
2 Correct 1242 ms 295768 KB Output is correct
3 Correct 307 ms 237136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 689 ms 364928 KB Output is correct
2 Correct 3210 ms 517368 KB Output is correct
3 Correct 312 ms 238420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 304 ms 236624 KB Output is correct
2 Correct 151 ms 236636 KB Output is correct
3 Correct 295 ms 236876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1596 ms 392360 KB Output is correct
2 Correct 2425 ms 488684 KB Output is correct
3 Correct 2483 ms 522272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 380 ms 284296 KB Output is correct
2 Correct 2266 ms 391252 KB Output is correct
3 Correct 2130 ms 482056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2404 ms 438420 KB Output is correct
2 Correct 2360 ms 524284 KB Output is correct
3 Correct 1704 ms 487880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1507 ms 432340 KB Output is correct
2 Correct 2612 ms 515008 KB Output is correct
3 Correct 2210 ms 518484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1410 ms 282740 KB Output is correct
2 Execution timed out 5063 ms 506524 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1813 ms 294484 KB Output is correct
2 Execution timed out 5064 ms 512516 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 496 ms 244052 KB Output is correct
2 Execution timed out 5042 ms 458100 KB Time limit exceeded
3 Halted 0 ms 0 KB -