# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
956272 | 2024-04-01T12:55:29 Z | Trisanu_Das | Sirni (COCI17_sirni) | C++17 | 1870 ms | 613712 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
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 235 ms | 312656 KB | Output is correct |
2 | Correct | 190 ms | 314964 KB | Output is correct |
3 | Correct | 130 ms | 312800 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 166 ms | 275596 KB | Output is correct |
2 | Correct | 558 ms | 309100 KB | Output is correct |
3 | Correct | 137 ms | 309160 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 121 ms | 311632 KB | Output is correct |
2 | Correct | 129 ms | 306544 KB | Output is correct |
3 | Correct | 123 ms | 310864 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 272 ms | 292032 KB | Output is correct |
2 | Correct | 630 ms | 316620 KB | Output is correct |
3 | Correct | 297 ms | 295876 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 145 ms | 281820 KB | Output is correct |
2 | Correct | 437 ms | 302300 KB | Output is correct |
3 | Correct | 386 ms | 290044 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 442 ms | 303004 KB | Output is correct |
2 | Correct | 720 ms | 331072 KB | Output is correct |
3 | Correct | 282 ms | 295320 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 301 ms | 279804 KB | Output is correct |
2 | Correct | 731 ms | 326108 KB | Output is correct |
3 | Correct | 297 ms | 294428 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 247 ms | 326500 KB | Output is correct |
2 | Correct | 1290 ms | 521104 KB | Output is correct |
3 | Correct | 257 ms | 328904 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 227 ms | 327148 KB | Output is correct |
2 | Correct | 1807 ms | 613712 KB | Output is correct |
3 | Correct | 301 ms | 333008 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 146 ms | 314920 KB | Output is correct |
2 | Correct | 1870 ms | 607672 KB | Output is correct |
3 | Correct | 338 ms | 296140 KB | Output is correct |