# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702448 | 2023-02-24T05:54:18 Z | GusterGoose27 | City Mapping (NOI18_citymapping) | C++11 | 3 ms | 596 KB |
// #include "citymapping.h" #include <bits/stdc++.h> #include "citymapping.h" using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int MAXN = 1000; int t = 0; mt19937 rng(6); ll dist[2][MAXN]; class bucket { public: vector<int> elems; int path_elem; int min_elem; ll mn_dist; bool m; bucket() {} bucket(int path, bool mn = 1) { min_elem = -1; path_elem = path; m = mn; mn_dist = 0; } void add(int i, ll d) { if (m && (min_elem == -1 || mn_dist > d)) { min_elem = i; mn_dist = d; } elems.push_back(i); } }; void make_ans(vector<int> &vals, int a[], int b[], int w[]) { if (vals.size() < 2) return; if (vals.size() == 2) { a[t] = vals[0]; b[t] = vals[1]; w[t] = get_distance(vals[0], vals[1]); t++; return; } int n = vals.size(); int f = rng()%n; // int mx = -1; for (int i = 0; i < n; i++) { if (i == f) continue; dist[0][i] = get_distance(vals[i], vals[f]); // if (mx == -1 || dist[0][i] > dist[0][mx]) mx = i; } int mx = f; while (mx == f) mx = rng()%n; dist[0][f] = 0; for (int i = 0; i < n; i++) { if (i == f || i == mx) continue; dist[1][i] = get_distance(vals[i], vals[mx]); } dist[1][mx] = 0; dist[1][f] = dist[0][mx]; vector<pli> path; map<ll, bucket> buckets; for (int i = 0; i < n; i++) { if (dist[0][i]+dist[1][i] == dist[0][mx]) { path.push_back(pli(dist[0][i], i)); buckets[dist[1][i]-dist[0][i]] = bucket(i, (i != f && i != mx)); } } sort(path.begin(), path.end()); for (int i = 0; i < path.size()-1; i++) { a[t] = vals[path[i].second]; b[t] = vals[path[i+1].second]; w[t] = dist[0][path[i+1].second]-dist[0][path[i].second]; t++; } for (int i = 0; i < n; i++) { if (dist[0][i]+dist[1][i] != dist[0][mx] || i == mx || i == f) buckets[dist[1][i]-dist[0][i]].add(vals[i], dist[0][i]); } for (auto it: buckets) { bucket bu = it.second; if (bu.m && bu.min_elem != -1) { a[t] = vals[bu.path_elem]; b[t] = bu.min_elem; w[t] = bu.mn_dist-dist[0][bu.path_elem]; // assert(bu.mn_dist > 0); assert(w[t] >= 0); t++; } } for (auto it: buckets) { make_ans(it.second.elems, a, b, w); } } void find_roads(int n, int q, int a[], int b[], int w[]) { vector<int> v(n); iota(v.begin(), v.end(), 1); make_ans(v, a, b, w); assert(t == n-1); // for (int i = 0; i < t; i++) assert(w[t] >= 0); return; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 468 KB | Correct: 6984 out of 500000 queries used. |
2 | Correct | 2 ms | 468 KB | Correct: 4155 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 8455 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 7452 out of 500000 queries used. |
5 | Correct | 2 ms | 468 KB | Correct: 8470 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 468 KB | Correct: 6984 out of 500000 queries used. |
2 | Correct | 2 ms | 468 KB | Correct: 4155 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 8455 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 7452 out of 500000 queries used. |
5 | Correct | 2 ms | 468 KB | Correct: 8470 out of 500000 queries used. |
6 | Correct | 1 ms | 596 KB | Correct: 2923 out of 500000 queries used. |
7 | Correct | 1 ms | 468 KB | Correct: 3697 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 8145 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 7872 out of 500000 queries used. |
10 | Correct | 2 ms | 468 KB | Correct: 7155 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Correct: 4700 out of 12000 queries used. |
2 | Correct | 2 ms | 596 KB | Correct: 7267 out of 12000 queries used. |
3 | Correct | 1 ms | 596 KB | Correct: 3641 out of 12000 queries used. |
4 | Correct | 2 ms | 580 KB | Correct: 3424 out of 12000 queries used. |
5 | Correct | 2 ms | 520 KB | Correct: 6191 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Correct: 4700 out of 12000 queries used. |
2 | Correct | 2 ms | 596 KB | Correct: 7267 out of 12000 queries used. |
3 | Correct | 1 ms | 596 KB | Correct: 3641 out of 12000 queries used. |
4 | Correct | 2 ms | 580 KB | Correct: 3424 out of 12000 queries used. |
5 | Correct | 2 ms | 520 KB | Correct: 6191 out of 12000 queries used. |
6 | Correct | 2 ms | 468 KB | Correct: 2634 out of 12000 queries used. |
7 | Correct | 2 ms | 468 KB | Correct: 5484 out of 12000 queries used. |
8 | Correct | 2 ms | 596 KB | Correct: 5799 out of 12000 queries used. |
9 | Correct | 2 ms | 596 KB | Correct: 6508 out of 12000 queries used. |
10 | Correct | 2 ms | 596 KB | Correct: 3623 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 468 KB | Correct: 6984 out of 500000 queries used. |
2 | Correct | 2 ms | 468 KB | Correct: 4155 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 8455 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 7452 out of 500000 queries used. |
5 | Correct | 2 ms | 468 KB | Correct: 8470 out of 500000 queries used. |
6 | Correct | 1 ms | 596 KB | Correct: 2923 out of 500000 queries used. |
7 | Correct | 1 ms | 468 KB | Correct: 3697 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 8145 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 7872 out of 500000 queries used. |
10 | Correct | 2 ms | 468 KB | Correct: 7155 out of 500000 queries used. |
11 | Correct | 2 ms | 596 KB | Correct: 4700 out of 12000 queries used. |
12 | Correct | 2 ms | 596 KB | Correct: 7267 out of 12000 queries used. |
13 | Correct | 1 ms | 596 KB | Correct: 3641 out of 12000 queries used. |
14 | Correct | 2 ms | 580 KB | Correct: 3424 out of 12000 queries used. |
15 | Correct | 2 ms | 520 KB | Correct: 6191 out of 12000 queries used. |
16 | Correct | 2 ms | 468 KB | Correct: 2634 out of 12000 queries used. |
17 | Correct | 2 ms | 468 KB | Correct: 5484 out of 12000 queries used. |
18 | Correct | 2 ms | 596 KB | Correct: 5799 out of 12000 queries used. |
19 | Correct | 2 ms | 596 KB | Correct: 6508 out of 12000 queries used. |
20 | Correct | 2 ms | 596 KB | Correct: 3623 out of 12000 queries used. |
21 | Correct | 2 ms | 468 KB | Correct: 8212 out of 25000 queries used. |
22 | Correct | 2 ms | 468 KB | Correct: 6228 out of 25000 queries used. |
23 | Correct | 1 ms | 468 KB | Correct: 5002 out of 25000 queries used. |
24 | Correct | 1 ms | 468 KB | Correct: 3517 out of 25000 queries used. |
25 | Correct | 2 ms | 468 KB | Correct: 8985 out of 25000 queries used. |
26 | Correct | 2 ms | 468 KB | Correct: 10589 out of 25000 queries used. |
27 | Correct | 2 ms | 468 KB | Correct: 7310 out of 25000 queries used. |
28 | Correct | 2 ms | 468 KB | Correct: 7825 out of 25000 queries used. |
29 | Correct | 2 ms | 468 KB | Correct: 7846 out of 25000 queries used. |
30 | Correct | 2 ms | 468 KB | Correct: 7633 out of 25000 queries used. |
31 | Correct | 2 ms | 468 KB | Correct: 8766 out of 25000 queries used. |
32 | Correct | 1 ms | 596 KB | Correct: 3993 out of 25000 queries used. |
33 | Correct | 2 ms | 468 KB | Correct: 8957 out of 25000 queries used. |
34 | Correct | 2 ms | 468 KB | Correct: 8638 out of 25000 queries used. |
35 | Correct | 2 ms | 468 KB | Correct: 8072 out of 25000 queries used. |
36 | Correct | 2 ms | 468 KB | Correct: 8795 out of 25000 queries used. |
37 | Correct | 2 ms | 468 KB | Correct: 8163 out of 25000 queries used. |
38 | Correct | 2 ms | 468 KB | Correct: 7330 out of 25000 queries used. |
39 | Correct | 2 ms | 468 KB | Correct: 9605 out of 25000 queries used. |
40 | Correct | 2 ms | 468 KB | Correct: 8273 out of 25000 queries used. |
41 | Correct | 2 ms | 468 KB | Correct: 7709 out of 25000 queries used. |
42 | Correct | 2 ms | 468 KB | Correct: 8004 out of 25000 queries used. |
43 | Correct | 3 ms | 596 KB | Correct: 4507 out of 25000 queries used. |
44 | Correct | 2 ms | 468 KB | Correct: 7555 out of 25000 queries used. |
45 | Correct | 2 ms | 468 KB | Correct: 7576 out of 25000 queries used. |
46 | Correct | 2 ms | 468 KB | Correct: 7259 out of 25000 queries used. |
47 | Correct | 2 ms | 468 KB | Correct: 8727 out of 25000 queries used. |
48 | Correct | 2 ms | 468 KB | Correct: 7727 out of 25000 queries used. |
49 | Correct | 2 ms | 468 KB | Correct: 8436 out of 25000 queries used. |
50 | Correct | 3 ms | 468 KB | Correct: 7721 out of 25000 queries used. |
51 | Correct | 2 ms | 468 KB | Correct: 7412 out of 25000 queries used. |
52 | Correct | 2 ms | 468 KB | Correct: 8158 out of 25000 queries used. |
53 | Correct | 2 ms | 468 KB | Correct: 7783 out of 25000 queries used. |
54 | Correct | 2 ms | 468 KB | Correct: 5812 out of 25000 queries used. |
55 | Correct | 2 ms | 468 KB | Correct: 7533 out of 25000 queries used. |
56 | Correct | 2 ms | 468 KB | Correct: 7449 out of 25000 queries used. |
57 | Correct | 2 ms | 468 KB | Correct: 7799 out of 25000 queries used. |
58 | Correct | 2 ms | 468 KB | Correct: 7854 out of 25000 queries used. |
59 | Correct | 2 ms | 468 KB | Correct: 7864 out of 25000 queries used. |
60 | Correct | 2 ms | 468 KB | Correct: 6561 out of 25000 queries used. |
61 | Correct | 3 ms | 468 KB | Correct: 8265 out of 25000 queries used. |
62 | Correct | 2 ms | 468 KB | Correct: 6784 out of 25000 queries used. |
63 | Correct | 2 ms | 468 KB | Correct: 8726 out of 25000 queries used. |
64 | Correct | 2 ms | 468 KB | Correct: 8539 out of 25000 queries used. |
65 | Correct | 2 ms | 468 KB | Correct: 4853 out of 25000 queries used. |
66 | Correct | 2 ms | 468 KB | Correct: 7233 out of 25000 queries used. |
67 | Correct | 2 ms | 468 KB | Correct: 2752 out of 25000 queries used. |
68 | Correct | 2 ms | 468 KB | Correct: 7215 out of 25000 queries used. |
69 | Correct | 1 ms | 468 KB | Correct: 4629 out of 25000 queries used. |
70 | Correct | 2 ms | 468 KB | Correct: 5650 out of 25000 queries used. |