답안 #887157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
887157 2023-12-13T22:57:52 Z Servant_of_the_Lord Sirni (COCI17_sirni) C++17
126 / 140
5000 ms 608848 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);
            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<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: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;
      |                      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 327 ms 236648 KB Output is correct
2 Correct 1105 ms 299400 KB Output is correct
3 Correct 311 ms 237280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 703 ms 372224 KB Output is correct
2 Correct 2983 ms 583444 KB Output is correct
3 Correct 310 ms 238420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 305 ms 236628 KB Output is correct
2 Correct 149 ms 236628 KB Output is correct
3 Correct 309 ms 236884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1676 ms 404572 KB Output is correct
2 Correct 2639 ms 546260 KB Output is correct
3 Correct 2817 ms 593572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 361 ms 284500 KB Output is correct
2 Correct 2468 ms 436060 KB Output is correct
3 Correct 2379 ms 505148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2229 ms 472292 KB Output is correct
2 Correct 2325 ms 608848 KB Output is correct
3 Correct 1563 ms 500164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1537 ms 457516 KB Output is correct
2 Correct 2706 ms 608240 KB Output is correct
3 Correct 2142 ms 570472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1018 ms 280976 KB Output is correct
2 Correct 4865 ms 554944 KB Output is correct
3 Correct 1146 ms 292380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1095 ms 292672 KB Output is correct
2 Execution timed out 5049 ms 600516 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 429 ms 243764 KB Output is correct
2 Correct 4653 ms 503544 KB Output is correct
3 Correct 2303 ms 579176 KB Output is correct