# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1024604 | 2024-07-16T08:33:22 Z | thinknoexit | City Mapping (NOI18_citymapping) | C++17 | 5 ms | 8572 KB |
#include "citymapping.h" #include <bits/stdc++.h> using namespace std; using ll = long long; const int N = 1010; mt19937 rnd(time(NULL)); int n; ll dis[N][N]; int A[N], B[N], W[N], tot; ll d(int i, int j) { if (i == j) return 0; if (!dis[i][j]) return dis[i][j] = dis[j][i] = get_distance(i, j); return dis[i][j]; } void play(vector<int>& v, int P) { int m = v.size(); if (m == 1) return; ll mx = 0; int U = 0, V = 0; for (auto& x : v) { if (d(P, x) > mx) { mx = d(P, x); U = x; } } mx = 0; for (auto& x : v) { if (d(U, x) > mx) { mx = d(U, x); V = x; } } // U, V is leaf ll all = d(U, V); vector<pair<ll, int>> in, rem; for (auto& x : v) { if (d(U, x) + d(x, V) == all) in.push_back({ d(U, x), x }); else { ll extra = (d(U, x) + d(x, V) - all) / 2; rem.push_back({ d(U, x) - extra, x }); } } sort(in.begin(), in.end()); sort(rem.begin(), rem.end()); vector<vector<int>> r; vector<int> p2; int p = 0; for (int i = 1;i < (int)in.size();i++) { A[tot] = in[i - 1].second; B[tot] = in[i].second; W[tot] = in[i].first - in[i - 1].first; tot++; vector<int> nw; ll mn = LLONG_MAX; int idx = 0; while (p < (int)rem.size() && rem[p].first == in[i].first) { int vl = rem[p].second; ll extra = (d(U, vl) + d(vl, V) - all) / 2; if (extra < mn) { mn = extra; idx = vl; } nw.push_back(vl); p++; } if (!nw.empty()) { A[tot] = idx; B[tot] = in[i].second; W[tot] = mn; tot++; for (auto& x : nw) { dis[idx][x] = dis[x][idx] = d(U, x) - mn - in[i].first; } r.push_back(nw); p2.push_back(idx); } } for (int i = 0;i < (int)r.size();i++) { play(r[i], p2[i]); } } void find_roads(int NN, int Q, int A[], int B[], int W[]) { n = NN; vector<int> init(n); iota(init.begin(), init.end(), 1); play(init, rnd() % n + 1); for (int i = 0;i < n - 1;i++) { A[i] = ::A[i]; B[i] = ::B[i]; W[i] = ::W[i]; //cout << A[i] << ' ' << B[i] << ' ' << W[i] << '\n'; } return; }
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8540 KB | Correct: 2991 out of 500000 queries used. |
2 | Correct | 2 ms | 7728 KB | Correct: 2994 out of 500000 queries used. |
3 | Correct | 3 ms | 8352 KB | Correct: 5959 out of 500000 queries used. |
4 | Correct | 3 ms | 8284 KB | Correct: 6649 out of 500000 queries used. |
5 | Correct | 3 ms | 8540 KB | Correct: 11954 out of 500000 queries used. |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8540 KB | Correct: 2991 out of 500000 queries used. |
2 | Correct | 2 ms | 7728 KB | Correct: 2994 out of 500000 queries used. |
3 | Correct | 3 ms | 8352 KB | Correct: 5959 out of 500000 queries used. |
4 | Correct | 3 ms | 8284 KB | Correct: 6649 out of 500000 queries used. |
5 | Correct | 3 ms | 8540 KB | Correct: 11954 out of 500000 queries used. |
6 | Correct | 3 ms | 8540 KB | Correct: 2982 out of 500000 queries used. |
7 | Correct | 4 ms | 8536 KB | Correct: 20409 out of 500000 queries used. |
8 | Correct | 3 ms | 8284 KB | Correct: 5996 out of 500000 queries used. |
9 | Correct | 5 ms | 8540 KB | Correct: 6991 out of 500000 queries used. |
10 | Correct | 3 ms | 8284 KB | Correct: 7106 out of 500000 queries used. |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 7772 KB | Correct: 2967 out of 12000 queries used. |
2 | Correct | 2 ms | 8364 KB | Correct: 2973 out of 12000 queries used. |
3 | Correct | 2 ms | 8028 KB | Correct: 2994 out of 12000 queries used. |
4 | Correct | 2 ms | 8284 KB | Correct: 2973 out of 12000 queries used. |
5 | Correct | 3 ms | 8028 KB | Correct: 2967 out of 12000 queries used. |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 7772 KB | Correct: 2967 out of 12000 queries used. |
2 | Correct | 2 ms | 8364 KB | Correct: 2973 out of 12000 queries used. |
3 | Correct | 2 ms | 8028 KB | Correct: 2994 out of 12000 queries used. |
4 | Correct | 2 ms | 8284 KB | Correct: 2973 out of 12000 queries used. |
5 | Correct | 3 ms | 8028 KB | Correct: 2967 out of 12000 queries used. |
6 | Correct | 2 ms | 7260 KB | Correct: 2988 out of 12000 queries used. |
7 | Correct | 3 ms | 8284 KB | Correct: 2982 out of 12000 queries used. |
8 | Correct | 3 ms | 8028 KB | Correct: 2994 out of 12000 queries used. |
9 | Correct | 3 ms | 7772 KB | Correct: 2985 out of 12000 queries used. |
10 | Correct | 3 ms | 8284 KB | Correct: 2976 out of 12000 queries used. |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 8540 KB | Correct: 2991 out of 500000 queries used. |
2 | Correct | 2 ms | 7728 KB | Correct: 2994 out of 500000 queries used. |
3 | Correct | 3 ms | 8352 KB | Correct: 5959 out of 500000 queries used. |
4 | Correct | 3 ms | 8284 KB | Correct: 6649 out of 500000 queries used. |
5 | Correct | 3 ms | 8540 KB | Correct: 11954 out of 500000 queries used. |
6 | Correct | 3 ms | 8540 KB | Correct: 2982 out of 500000 queries used. |
7 | Correct | 4 ms | 8536 KB | Correct: 20409 out of 500000 queries used. |
8 | Correct | 3 ms | 8284 KB | Correct: 5996 out of 500000 queries used. |
9 | Correct | 5 ms | 8540 KB | Correct: 6991 out of 500000 queries used. |
10 | Correct | 3 ms | 8284 KB | Correct: 7106 out of 500000 queries used. |
11 | Correct | 3 ms | 7772 KB | Correct: 2967 out of 12000 queries used. |
12 | Correct | 2 ms | 8364 KB | Correct: 2973 out of 12000 queries used. |
13 | Correct | 2 ms | 8028 KB | Correct: 2994 out of 12000 queries used. |
14 | Correct | 2 ms | 8284 KB | Correct: 2973 out of 12000 queries used. |
15 | Correct | 3 ms | 8028 KB | Correct: 2967 out of 12000 queries used. |
16 | Correct | 2 ms | 7260 KB | Correct: 2988 out of 12000 queries used. |
17 | Correct | 3 ms | 8284 KB | Correct: 2982 out of 12000 queries used. |
18 | Correct | 3 ms | 8028 KB | Correct: 2994 out of 12000 queries used. |
19 | Correct | 3 ms | 7772 KB | Correct: 2985 out of 12000 queries used. |
20 | Correct | 3 ms | 8284 KB | Correct: 2976 out of 12000 queries used. |
21 | Correct | 2 ms | 7772 KB | Correct: 2982 out of 25000 queries used. |
22 | Correct | 3 ms | 8260 KB | Correct: 6208 out of 25000 queries used. |
23 | Correct | 2 ms | 8284 KB | Correct: 3034 out of 25000 queries used. |
24 | Correct | 3 ms | 8540 KB | Correct: 4400 out of 25000 queries used. |
25 | Correct | 3 ms | 8284 KB | Correct: 6013 out of 25000 queries used. |
26 | Correct | 3 ms | 8284 KB | Correct: 5789 out of 25000 queries used. |
27 | Correct | 3 ms | 8284 KB | Correct: 5875 out of 25000 queries used. |
28 | Correct | 3 ms | 8284 KB | Correct: 6209 out of 25000 queries used. |
29 | Correct | 3 ms | 8500 KB | Correct: 6368 out of 25000 queries used. |
30 | Correct | 3 ms | 8284 KB | Correct: 6707 out of 25000 queries used. |
31 | Correct | 3 ms | 8284 KB | Correct: 6686 out of 25000 queries used. |
32 | Correct | 2 ms | 7516 KB | Correct: 2979 out of 25000 queries used. |
33 | Correct | 3 ms | 8372 KB | Correct: 6663 out of 25000 queries used. |
34 | Correct | 3 ms | 8284 KB | Correct: 6656 out of 25000 queries used. |
35 | Correct | 3 ms | 8284 KB | Correct: 6678 out of 25000 queries used. |
36 | Correct | 3 ms | 8284 KB | Correct: 6727 out of 25000 queries used. |
37 | Correct | 3 ms | 8284 KB | Correct: 6623 out of 25000 queries used. |
38 | Correct | 3 ms | 8284 KB | Correct: 6754 out of 25000 queries used. |
39 | Correct | 3 ms | 8284 KB | Correct: 6657 out of 25000 queries used. |
40 | Correct | 3 ms | 8284 KB | Correct: 6712 out of 25000 queries used. |
41 | Correct | 3 ms | 8284 KB | Correct: 6671 out of 25000 queries used. |
42 | Correct | 3 ms | 8284 KB | Correct: 6680 out of 25000 queries used. |
43 | Correct | 2 ms | 7312 KB | Correct: 2988 out of 25000 queries used. |
44 | Correct | 2 ms | 8328 KB | Correct: 6605 out of 25000 queries used. |
45 | Correct | 2 ms | 8332 KB | Correct: 6599 out of 25000 queries used. |
46 | Correct | 2 ms | 8284 KB | Correct: 6606 out of 25000 queries used. |
47 | Correct | 3 ms | 8504 KB | Correct: 6682 out of 25000 queries used. |
48 | Correct | 3 ms | 8312 KB | Correct: 6737 out of 25000 queries used. |
49 | Correct | 4 ms | 8284 KB | Correct: 6694 out of 25000 queries used. |
50 | Correct | 4 ms | 8284 KB | Correct: 6692 out of 25000 queries used. |
51 | Correct | 3 ms | 8284 KB | Correct: 6687 out of 25000 queries used. |
52 | Correct | 4 ms | 8284 KB | Correct: 6670 out of 25000 queries used. |
53 | Correct | 4 ms | 8280 KB | Correct: 6988 out of 25000 queries used. |
54 | Correct | 5 ms | 8572 KB | Correct: 22017 out of 25000 queries used. |
55 | Correct | 4 ms | 8476 KB | Correct: 6677 out of 25000 queries used. |
56 | Correct | 4 ms | 8284 KB | Correct: 6734 out of 25000 queries used. |
57 | Correct | 3 ms | 8284 KB | Correct: 7030 out of 25000 queries used. |
58 | Correct | 3 ms | 8284 KB | Correct: 6602 out of 25000 queries used. |
59 | Correct | 3 ms | 8284 KB | Correct: 6609 out of 25000 queries used. |
60 | Correct | 3 ms | 8284 KB | Correct: 8425 out of 25000 queries used. |
61 | Correct | 3 ms | 8284 KB | Correct: 7827 out of 25000 queries used. |
62 | Correct | 3 ms | 8284 KB | Correct: 7212 out of 25000 queries used. |
63 | Correct | 3 ms | 8540 KB | Correct: 7897 out of 25000 queries used. |
64 | Correct | 3 ms | 8284 KB | Correct: 7474 out of 25000 queries used. |
65 | Correct | 3 ms | 8284 KB | Correct: 10208 out of 25000 queries used. |
66 | Correct | 3 ms | 8280 KB | Correct: 7354 out of 25000 queries used. |
67 | Correct | 2 ms | 8284 KB | Correct: 3335 out of 25000 queries used. |
68 | Correct | 4 ms | 8540 KB | Correct: 24921 out of 25000 queries used. |
69 | Correct | 4 ms | 8540 KB | Correct: 15612 out of 25000 queries used. |
70 | Correct | 4 ms | 8472 KB | Correct: 16377 out of 25000 queries used. |