# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887143 | 2023-12-13T21:30:43 Z | Servant_of_the_Lord | Sirni (COCI17_sirni) | C++17 | 5000 ms | 611312 KB |
#include <bits/stdc++.h> #pragma GCC optimize("O2") #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<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); if(s.empty())break; } cout<<a<<'\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 273 ms | 236532 KB | Output is correct |
2 | Correct | 1196 ms | 299536 KB | Output is correct |
3 | Correct | 278 ms | 237140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 676 ms | 372548 KB | Output is correct |
2 | Correct | 3542 ms | 583452 KB | Output is correct |
3 | Correct | 285 ms | 238620 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 273 ms | 236688 KB | Output is correct |
2 | Correct | 135 ms | 236628 KB | Output is correct |
3 | Correct | 271 ms | 237080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1618 ms | 408064 KB | Output is correct |
2 | Correct | 2664 ms | 549460 KB | Output is correct |
3 | Correct | 2706 ms | 594840 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 357 ms | 285012 KB | Output is correct |
2 | Correct | 2376 ms | 428388 KB | Output is correct |
3 | Correct | 2257 ms | 507040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2512 ms | 475336 KB | Output is correct |
2 | Correct | 2655 ms | 611312 KB | Output is correct |
3 | Correct | 1794 ms | 503488 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1589 ms | 458220 KB | Output is correct |
2 | Correct | 2974 ms | 608852 KB | Output is correct |
3 | Correct | 2403 ms | 572292 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1603 ms | 284620 KB | Output is correct |
2 | Execution timed out | 5066 ms | 558604 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1674 ms | 296528 KB | Output is correct |
2 | Execution timed out | 5042 ms | 602344 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 487 ms | 244564 KB | Output is correct |
2 | Execution timed out | 5086 ms | 503796 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |