# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
568424 | 2022-05-25T11:54:15 Z | shahriarkhan | Sirni (COCI17_sirni) | C++14 | 584 ms | 300428 KB |
#include<bits/stdc++.h> using namespace std ; const int MX = 1e7 + 5 ; int nex[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] = {0} ; long long ans = 0 ; for(int i = 1 ; i <= n ; ++i) { scanf("%d",&p[i]) ; if(!nex[p[i]]) nex[p[i]] = i ; } for(int i = MX - 2 ; i >= 0 ; --i) { if(!nex[i]) nex[i] = nex[i+1] ; } dsu D ; D.init(n+2) ; sort(p+1,p+n+1) ; for(int i = 1 ; i <= n ; ++i) { if(p[i-1]==p[i]) continue ; 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({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 | Incorrect | 186 ms | 274292 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 222 ms | 274376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 188 ms | 274328 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 401 ms | 287940 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 216 ms | 276672 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 584 ms | 300428 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 349 ms | 278972 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 388 ms | 290948 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 416 ms | 295096 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 264 ms | 276900 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |