답안 #887164

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887164 2023-12-13T23:08:48 Z Servant_of_the_Lord Sirni (COCI17_sirni) C++17
112 / 140
5000 ms 607516 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<pair<ll,ll>>s;
            for(ll i=0;i<x;i++)
            {
                cin>>y;
                s.insert({y,i});
            }
            vector<vector<ll>>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);
            }
            cout<<a<<'\n';
        }

Compilation message

sirni.cpp:8:9: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 |         main()
      |         ^~~~
sirni.cpp: In function 'int main()':
sirni.cpp:50:33: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long 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:20: warning: unused variable 'z' [-Wunused-variable]
   13 |             ll x,y,z,a,b,c;
      |                    ^
sirni.cpp:13:24: warning: unused variable 'b' [-Wunused-variable]
   13 |             ll x,y,z,a,b,c;
      |                        ^
sirni.cpp:13:26: warning: unused variable 'c' [-Wunused-variable]
   13 |             ll x,y,z,a,b,c;
      |                          ^
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 236624 KB Output is correct
2 Correct 1014 ms 299372 KB Output is correct
3 Correct 295 ms 237076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 696 ms 372392 KB Output is correct
2 Correct 2846 ms 583508 KB Output is correct
3 Correct 306 ms 238420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 300 ms 236520 KB Output is correct
2 Correct 148 ms 236428 KB Output is correct
3 Correct 294 ms 236884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1441 ms 403800 KB Output is correct
2 Correct 2414 ms 545824 KB Output is correct
3 Correct 2552 ms 593228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 357 ms 284244 KB Output is correct
2 Correct 2244 ms 435692 KB Output is correct
3 Correct 2101 ms 504936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2285 ms 471488 KB Output is correct
2 Correct 2390 ms 607516 KB Output is correct
3 Correct 1580 ms 499272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1585 ms 457116 KB Output is correct
2 Correct 2695 ms 607472 KB Output is correct
3 Correct 2185 ms 570036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1045 ms 280148 KB Output is correct
2 Execution timed out 5038 ms 554208 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1140 ms 291888 KB Output is correct
2 Execution timed out 5040 ms 599908 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 451 ms 243536 KB Output is correct
2 Correct 4691 ms 502944 KB Output is correct
3 Correct 2444 ms 578676 KB Output is correct