# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
669189 | Quan2003 | Sirni (COCI17_sirni) | C++17 | 328 ms | 475684 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>
using namespace std;
typedef long long ll;
const int sz=1e7+1;
const int mod=1e9+7;
int n,q,timer;
long long d;
long long a[sz];
long long p[sz];
long long dp[sz];
int freq[sz];
int cnt[sz];
int cntr[sz];
vector<pair<int,int>>edge[sz];
int parent[sz];
int compsize[sz];
void init(int n){
for (int i = 1; i <= n; i++){
parent[i] = i;
compsize[i] = 1;
}
}
int find(int a){
if (a == parent[a]) return a;
return parent[a] = find(parent[a]);
}
void unite(int a, int b){
int roota = find(a), rootb = find(b);
if (roota == rootb) return ;
if (compsize[roota] > compsize[rootb]) swap(roota, rootb);
parent[roota] = rootb;
compsize[rootb] += compsize[roota];
}
int main(){
cin>>n;
int bound = 0;
for(int i = 1; i <= n; i++){
int x; cin>>x; a[x]++;
bound = max(bound,x);
}
init(bound);
for(int i = bound ; i > 0; i--){
if(!a[i]) p[i] = p[i+1];
else p[i] = i;
}
for(int i = 1; i <= bound; i++){
if(!a[i]) continue;
for(int j = i; j <= bound; j+=i){
int l = (i == j) ? i + 1: j;
int rr = min(i + j - 1,bound);
if(p[l] >= rr) edge[p[l]%i].push_back({p[l],i});
}
}
int ans = 0;
for(int i = 1; i <= bound; i++){
for(int j = 0; j < edge[i].size(); j++){
int u = edge[i][j].first;
int v = edge[i][j].second;
if(find(u) == find(v)) continue;
unite(u,v);
ans+=i;
}
}
cout<<ans<<endl;
}
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... |