# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887166 | 2023-12-13T23:11:46 Z | Servant_of_the_Lord | Sirni (COCI17_sirni) | C++17 | 2636 ms | 607868 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]);}; y=x; 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; y--; 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()||y==1)break; } cout<<a<<'\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 207 ms | 236604 KB | Output is correct |
2 | Correct | 508 ms | 299388 KB | Output is correct |
3 | Correct | 97 ms | 237056 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 690 ms | 372296 KB | Output is correct |
2 | Correct | 1499 ms | 583684 KB | Output is correct |
3 | Correct | 63 ms | 238416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 208 ms | 236624 KB | Output is correct |
2 | Correct | 83 ms | 236628 KB | Output is correct |
3 | Correct | 132 ms | 236880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1449 ms | 403812 KB | Output is correct |
2 | Correct | 2266 ms | 545832 KB | Output is correct |
3 | Correct | 2258 ms | 593024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 305 ms | 284240 KB | Output is correct |
2 | Correct | 2120 ms | 435668 KB | Output is correct |
3 | Correct | 2142 ms | 504488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2234 ms | 471560 KB | Output is correct |
2 | Correct | 2167 ms | 607868 KB | Output is correct |
3 | Correct | 1370 ms | 499472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1550 ms | 457040 KB | Output is correct |
2 | Correct | 2614 ms | 607788 KB | Output is correct |
3 | Correct | 1952 ms | 570004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 705 ms | 279948 KB | Output is correct |
2 | Correct | 1817 ms | 554176 KB | Output is correct |
3 | Correct | 768 ms | 291576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 452 ms | 291924 KB | Output is correct |
2 | Correct | 2555 ms | 600216 KB | Output is correct |
3 | Correct | 705 ms | 441760 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 333 ms | 243664 KB | Output is correct |
2 | Correct | 2636 ms | 502696 KB | Output is correct |
3 | Correct | 2138 ms | 578424 KB | Output is correct |