# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887145 | 2023-12-13T21:32:48 Z | Servant_of_the_Lord | Sirni (COCI17_sirni) | C++17 | 5000 ms | 611244 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); z=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; z--; 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()||z==0)break; } cout<<a<<'\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 219 ms | 236628 KB | Output is correct |
2 | Correct | 1192 ms | 299564 KB | Output is correct |
3 | Correct | 96 ms | 237180 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 686 ms | 372232 KB | Output is correct |
2 | Correct | 3593 ms | 583524 KB | Output is correct |
3 | Correct | 293 ms | 238416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 196 ms | 236628 KB | Output is correct |
2 | Correct | 132 ms | 236624 KB | Output is correct |
3 | Correct | 133 ms | 236884 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1618 ms | 407868 KB | Output is correct |
2 | Correct | 2635 ms | 549148 KB | Output is correct |
3 | Correct | 2718 ms | 594472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 362 ms | 285012 KB | Output is correct |
2 | Correct | 2376 ms | 428144 KB | Output is correct |
3 | Correct | 2306 ms | 507040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2684 ms | 475328 KB | Output is correct |
2 | Correct | 2611 ms | 611244 KB | Output is correct |
3 | Correct | 1728 ms | 503220 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1555 ms | 458632 KB | Output is correct |
2 | Correct | 2927 ms | 609020 KB | Output is correct |
3 | Correct | 2375 ms | 572480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1541 ms | 284636 KB | Output is correct |
2 | Execution timed out | 5072 ms | 558500 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1680 ms | 296272 KB | Output is correct |
2 | Execution timed out | 5123 ms | 602280 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 463 ms | 244480 KB | Output is correct |
2 | Execution timed out | 5040 ms | 503776 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |