# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568418 | 2022-05-25T11:46:30 Z | shahriarkhan | Sirni (COCI17_sirni) | C++14 | 1763 ms | 786432 KB |
#include<bits/stdc++.h> using namespace std ; const int MX = 2e7 + 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]] = p[i] ; } for(int i = MX - 3 ; 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+(j==p[i])]) continue ; int rem = nex[j+(j==p[i])]%p[i] ; val[rem].push_back({p[i],nex[j+(j==p[i])]}) ; } } 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 | Correct | 438 ms | 708616 KB | Output is correct |
2 | Correct | 569 ms | 739240 KB | Output is correct |
3 | Correct | 447 ms | 709068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 546 ms | 704932 KB | Output is correct |
2 | Runtime error | 628 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 436 ms | 708832 KB | Output is correct |
2 | Correct | 439 ms | 707304 KB | Output is correct |
3 | Correct | 426 ms | 709012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 716 ms | 718680 KB | Output is correct |
2 | Correct | 1305 ms | 746408 KB | Output is correct |
3 | Correct | 799 ms | 732248 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 503 ms | 710796 KB | Output is correct |
2 | Correct | 1132 ms | 731996 KB | Output is correct |
3 | Correct | 856 ms | 717236 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1022 ms | 730524 KB | Output is correct |
2 | Correct | 1629 ms | 765088 KB | Output is correct |
3 | Correct | 783 ms | 727956 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 809 ms | 709144 KB | Output is correct |
2 | Correct | 1763 ms | 767224 KB | Output is correct |
3 | Correct | 794 ms | 728988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 624 ms | 758020 KB | Output is correct |
2 | Runtime error | 627 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 642 ms | 761700 KB | Output is correct |
2 | Runtime error | 867 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 474 ms | 741332 KB | Output is correct |
2 | Runtime error | 1140 ms | 786432 KB | Execution killed with signal 9 |
3 | Halted | 0 ms | 0 KB | - |