# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887143 | Servant_of_the_Lord | Sirni (COCI17_sirni) | C++17 | 5086 ms | 611312 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |