# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568415 | 2022-05-25T11:39:50 Z | shahriarkhan | Sirni (COCI17_sirni) | C++14 | 595 ms | 409832 KB |
#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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 260 ms | 356332 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 271 ms | 352752 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 244 ms | 356556 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 395 ms | 367036 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 269 ms | 358440 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 595 ms | 379172 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 377 ms | 357352 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 411 ms | 406456 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 406 ms | 409832 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 270 ms | 389068 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |