# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
55318 | 2018-07-07T01:09:11 Z | IvanC | Sirni (COCI17_sirni) | C++17 | 5000 ms | 521444 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> ii; const int MAXN = 1e7 + 1; int pai[MAXN],proximo[MAXN],N; vector<int> ordenado; vector<ii> Kruskal[MAXN]; int find(int x){ if(x == pai[x]) return x; return pai[x] = find(pai[x]); } void join(int x,int y){ x = find(x);y = find(y); if(x == y) return; if(rand() & 1) swap(x,y); pai[y] = x; } int main(){ scanf("%d",&N); for(int i = 1;i<=N;i++){ int x; scanf("%d",&x); pai[x] = x; } for(int i = 1;i<MAXN;i++){ if(pai[i] == 0) continue; ordenado.push_back(i); for(int j = 2*i;j<MAXN;j+=i) if(pai[j] != 0) join(i,j); } int ultimo_visto = ordenado.back(); for(int i = MAXN-1;i>=1;i--){ proximo[i] = ultimo_visto; if(!ordenado.empty() && ordenado.back() == i){ ultimo_visto = i; ordenado.pop_back(); } } for(int i = 1;i<MAXN;i++){ if(pai[i] == 0) continue; ultimo_visto = -1; for(int j = i;j<MAXN;j+=i){ int candidato = proximo[j]; if(candidato == ultimo_visto) continue; ultimo_visto = candidato; Kruskal[candidato % i].push_back(ii(i,candidato)); } } ll total = 0; for(int w = 0;w<MAXN;w++){ for(ii davez : Kruskal[w]){ int u = davez.first, v = davez.second; if(find(u) != find(v)){ join(u,v); total += w; } } } printf("%lld\n",total); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 340 ms | 278136 KB | Output is correct |
2 | Correct | 416 ms | 279016 KB | Output is correct |
3 | Correct | 312 ms | 279016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 444 ms | 279016 KB | Output is correct |
2 | Correct | 839 ms | 279016 KB | Output is correct |
3 | Correct | 321 ms | 279016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 313 ms | 279016 KB | Output is correct |
2 | Correct | 330 ms | 279016 KB | Output is correct |
3 | Correct | 319 ms | 279016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 739 ms | 290336 KB | Output is correct |
2 | Correct | 1653 ms | 315124 KB | Output is correct |
3 | Correct | 772 ms | 315124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 376 ms | 315124 KB | Output is correct |
2 | Correct | 1290 ms | 315124 KB | Output is correct |
3 | Correct | 854 ms | 315124 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1155 ms | 315124 KB | Output is correct |
2 | Correct | 1794 ms | 330192 KB | Output is correct |
3 | Correct | 751 ms | 330192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 660 ms | 330192 KB | Output is correct |
2 | Correct | 1768 ms | 330192 KB | Output is correct |
3 | Correct | 758 ms | 330192 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 699 ms | 330192 KB | Output is correct |
2 | Correct | 4667 ms | 520184 KB | Output is correct |
3 | Correct | 654 ms | 520184 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 567 ms | 520184 KB | Output is correct |
2 | Execution timed out | 5067 ms | 521444 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 389 ms | 521444 KB | Output is correct |
2 | Execution timed out | 5074 ms | 521444 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |