Submission #568415

#TimeUsernameProblemLanguageResultExecution timeMemory
568415shahriarkhanSirni (COCI17_sirni)C++14
0 / 140
595 ms409832 KiB
#include<bits/stdc++.h> using namespace std ; const int MX = 1e7 + 5 ; int nex[MX] , vis[MX] ; vector<pair<int,int> > val[MX] ; struct dsu { vector<int> sz , par ; void init(int n) { sz = vector<int> (n+2,0) ; par = vector<int> (n+2,0) ; for(int i = 1 ; i <= n ; ++i) { par[i] = i , sz[i] = 1 ; } } int find_root(int a) { if(par[a]==a) return a ; return par[a] = find_root(par[a]) ; } int union_edge(int u , int v) { int root_u = find_root(u) , root_v = find_root(v) ; if(root_u==root_v) return 0 ; if(sz[root_v]>sz[root_u]) swap(root_u,root_v) ; sz[root_u] += sz[root_v] ; par[root_v] = root_u ; return 1 ; } }; int main() { int n ; scanf("%d",&n) ; int p[n+2] ; long long ans = 0 ; for(int i = 1 ; i <= n ; ++i) { scanf("%d",&p[i]) ; nex[p[i]-1] = p[i] ; } for(int i = MX - 2 ; i >= 0 ; --i) { if(!nex[i]) nex[i] = nex[i+1] ; } dsu D ; D.init(MX) ; for(int i = 1 ; i <= n ; ++i) { if(vis[p[i]]) continue ; vis[p[i]] = 1 ; for(int j = p[i] ; j < MX ; j += p[i]) { if(!nex[j]) continue ; int rem = nex[j]%p[i] ; val[rem].push_back({p[i],nex[j]}) ; } } for(int i = 0 ; i < MX ; ++i) { for(pair<int,int> f : val[i]) { int st = D.union_edge(f.first,f.second) ; if(st) ans += i ; } } printf("%lld\n",ans) ; return 0 ; }

Compilation message (stderr)

sirni.cpp: In function 'int main()':
sirni.cpp:41:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |     scanf("%d",&n) ;
      |     ~~~~~^~~~~~~~~
sirni.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         scanf("%d",&p[i]) ;
      |         ~~~~~^~~~~~~~~~~~
#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...