Submission #887158

# Submission time Handle Problem Language Result Execution time Memory
887158 2023-12-13T23:00:20 Z Servant_of_the_Lord Sirni (COCI17_sirni) C++17
42 / 140
4613 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<pair<ll,ll>>s;
        for(ll i=0;i<x;i++)
        {
            cin>>y;
            s.insert({y,i});
        }
        vector<vector<short>>v(10'000'000);
        for(pair<ll,ll> i:s)
        {
            if(v[i.first-1].empty())
            {
                for(ll j=i.first-1;j<10'000'000;j+=i.first)
                {
                    v[j].push_back(i.second);
                }
            }
        }
        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(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<pair<ll,ll>>e;
            for(pair<ll,ll> j:s)
            {
                for(ll k=0;k<v[j.first-i-1].size();k++)
                {
                    if(u(j.second,v[j.first-i-1][k]))
                    {
                        a+=i;
                    }
                }
                if(j.first-i-1==0||t[j.first-i-1])e.push_back(j);
                t[j.first-i-1]=1;
            }
            for(auto j:e)s.erase(j);
            if(s.empty())break;
        }
        cout<<a<<'\n';
    }

Compilation message

sirni.cpp:8:5: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 |     main()
      |     ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:50:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |                 for(ll k=0;k<v[j.first-i-1].size();k++)
      |                            ~^~~~~~~~~~~~~~~~~~~~~~
sirni.cpp:13:16: warning: unused variable 'z' [-Wunused-variable]
   13 |         ll x,y,z,a,b,c;
      |                ^
sirni.cpp:13:20: warning: unused variable 'b' [-Wunused-variable]
   13 |         ll x,y,z,a,b,c;
      |                    ^
sirni.cpp:13:22: warning: unused variable 'c' [-Wunused-variable]
   13 |         ll x,y,z,a,b,c;
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 528 ms 236484 KB Output is correct
2 Correct 1215 ms 295252 KB Output is correct
3 Correct 552 ms 237140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 656 ms 364324 KB Output is correct
2 Correct 2710 ms 513432 KB Output is correct
3 Correct 538 ms 238420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 543 ms 236628 KB Output is correct
2 Correct 293 ms 236628 KB Output is correct
3 Correct 550 ms 236892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1292 ms 786432 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 353 ms 283736 KB Output is correct
2 Runtime error 2110 ms 781424 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4230 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3814 ms 786432 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 456 ms 566808 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 484 ms 590920 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 724 ms 243656 KB Output is correct
2 Runtime error 4613 ms 786432 KB Execution killed with signal 9
3 Halted 0 ms 0 KB -