Submission #881851

#TimeUsernameProblemLanguageResultExecution timeMemory
881851boyliguanhanSirni (COCI17_sirni)C++17
0 / 140
5102 ms259684 KiB
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize(2) int nxt[10001000], p[100100],pa[100100],n,mx,ans; set<tuple<int,int,int>> edges; int abp(int n) { return (pa[n]?pa[n]=abp(pa[n]):n); } bool un(int a, int b) { a=abp(a); b=abp(b); if(a==b) return 0; pa[a]=b; return 1; } int main() { cin.sync_with_stdio(false); cin.tie(nullptr); cin >> n; for(int i = 1; i <= n; i++) cin >> p[i], mx=max(mx,p[i]),nxt[p[i]]=i; for(int i = mx; i--;) if(!nxt[i]) nxt[i]=nxt[i+1]; for(int i = 1; i <= n; i++) for(int j = 2*p[i]; j <= mx; j++) if(nxt[j]) edges.insert({p[nxt[j]]%p[i],i,nxt[j]}); else break; for(auto [w,u,v]: edges) { if(w>mx/2) break; if(un(u,v)) ans+=w; } cout << ans << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...