# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702450 | 2023-02-24T05:56:41 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[], int f = -1) { 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(); if (f == -1) f = rng()%n; else { for (int i = 0; i < vals.size(); i++) { if (vals[i] == f) { f = i; break; } } } // 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) { if (it.second.m) make_ans(it.second.elems, a, b, w, it.second.min_elem); else 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: 4924 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 9961 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 8492 out of 500000 queries used. |
5 | Correct | 3 ms | 468 KB | Correct: 8325 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: 4924 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 9961 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 8492 out of 500000 queries used. |
5 | Correct | 3 ms | 468 KB | Correct: 8325 out of 500000 queries used. |
6 | Correct | 2 ms | 596 KB | Correct: 2923 out of 500000 queries used. |
7 | Correct | 2 ms | 468 KB | Correct: 3494 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 7671 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 8544 out of 500000 queries used. |
10 | Correct | 3 ms | 468 KB | Correct: 7732 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 | 576 KB | Correct: 3424 out of 12000 queries used. |
5 | Correct | 1 ms | 468 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 | 576 KB | Correct: 3424 out of 12000 queries used. |
5 | Correct | 1 ms | 468 KB | Correct: 6191 out of 12000 queries used. |
6 | Correct | 1 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 | 468 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: 4924 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 9961 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 8492 out of 500000 queries used. |
5 | Correct | 3 ms | 468 KB | Correct: 8325 out of 500000 queries used. |
6 | Correct | 2 ms | 596 KB | Correct: 2923 out of 500000 queries used. |
7 | Correct | 2 ms | 468 KB | Correct: 3494 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 7671 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 8544 out of 500000 queries used. |
10 | Correct | 3 ms | 468 KB | Correct: 7732 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 | 576 KB | Correct: 3424 out of 12000 queries used. |
15 | Correct | 1 ms | 468 KB | Correct: 6191 out of 12000 queries used. |
16 | Correct | 1 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 | 468 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: 5312 out of 25000 queries used. |
23 | Correct | 2 ms | 468 KB | Correct: 6037 out of 25000 queries used. |
24 | Correct | 2 ms | 468 KB | Correct: 3482 out of 25000 queries used. |
25 | Correct | 2 ms | 468 KB | Correct: 11430 out of 25000 queries used. |
26 | Correct | 2 ms | 468 KB | Correct: 10103 out of 25000 queries used. |
27 | Correct | 2 ms | 468 KB | Correct: 8150 out of 25000 queries used. |
28 | Correct | 2 ms | 468 KB | Correct: 7922 out of 25000 queries used. |
29 | Correct | 2 ms | 468 KB | Correct: 8090 out of 25000 queries used. |
30 | Correct | 2 ms | 468 KB | Correct: 8226 out of 25000 queries used. |
31 | Correct | 2 ms | 468 KB | Correct: 10181 out of 25000 queries used. |
32 | Correct | 2 ms | 596 KB | Correct: 3993 out of 25000 queries used. |
33 | Correct | 2 ms | 468 KB | Correct: 9964 out of 25000 queries used. |
34 | Correct | 2 ms | 468 KB | Correct: 8042 out of 25000 queries used. |
35 | Correct | 2 ms | 468 KB | Correct: 9769 out of 25000 queries used. |
36 | Correct | 2 ms | 488 KB | Correct: 8433 out of 25000 queries used. |
37 | Correct | 2 ms | 468 KB | Correct: 8930 out of 25000 queries used. |
38 | Correct | 2 ms | 468 KB | Correct: 8080 out of 25000 queries used. |
39 | Correct | 2 ms | 468 KB | Correct: 10838 out of 25000 queries used. |
40 | Correct | 2 ms | 468 KB | Correct: 8908 out of 25000 queries used. |
41 | Correct | 2 ms | 468 KB | Correct: 8288 out of 25000 queries used. |
42 | Correct | 2 ms | 468 KB | Correct: 8354 out of 25000 queries used. |
43 | Correct | 2 ms | 596 KB | Correct: 4507 out of 25000 queries used. |
44 | Correct | 2 ms | 468 KB | Correct: 8377 out of 25000 queries used. |
45 | Correct | 3 ms | 468 KB | Correct: 8613 out of 25000 queries used. |
46 | Correct | 2 ms | 468 KB | Correct: 8144 out of 25000 queries used. |
47 | Correct | 2 ms | 468 KB | Correct: 9435 out of 25000 queries used. |
48 | Correct | 2 ms | 468 KB | Correct: 8621 out of 25000 queries used. |
49 | Correct | 2 ms | 468 KB | Correct: 8385 out of 25000 queries used. |
50 | Correct | 2 ms | 468 KB | Correct: 7987 out of 25000 queries used. |
51 | Correct | 2 ms | 468 KB | Correct: 8792 out of 25000 queries used. |
52 | Correct | 2 ms | 468 KB | Correct: 8330 out of 25000 queries used. |
53 | Correct | 2 ms | 468 KB | Correct: 7919 out of 25000 queries used. |
54 | Correct | 2 ms | 548 KB | Correct: 7565 out of 25000 queries used. |
55 | Correct | 2 ms | 468 KB | Correct: 8163 out of 25000 queries used. |
56 | Correct | 2 ms | 468 KB | Correct: 7959 out of 25000 queries used. |
57 | Correct | 2 ms | 468 KB | Correct: 8265 out of 25000 queries used. |
58 | Correct | 2 ms | 468 KB | Correct: 8616 out of 25000 queries used. |
59 | Correct | 2 ms | 468 KB | Correct: 8333 out of 25000 queries used. |
60 | Correct | 1 ms | 468 KB | Correct: 5766 out of 25000 queries used. |
61 | Correct | 2 ms | 468 KB | Correct: 7273 out of 25000 queries used. |
62 | Correct | 2 ms | 468 KB | Correct: 7199 out of 25000 queries used. |
63 | Correct | 2 ms | 468 KB | Correct: 8060 out of 25000 queries used. |
64 | Correct | 2 ms | 468 KB | Correct: 6961 out of 25000 queries used. |
65 | Correct | 2 ms | 468 KB | Correct: 4203 out of 25000 queries used. |
66 | Correct | 2 ms | 508 KB | Correct: 7154 out of 25000 queries used. |
67 | Correct | 2 ms | 468 KB | Correct: 2548 out of 25000 queries used. |
68 | Correct | 1 ms | 468 KB | Correct: 4933 out of 25000 queries used. |
69 | Correct | 1 ms | 468 KB | Correct: 3562 out of 25000 queries used. |
70 | Correct | 2 ms | 468 KB | Correct: 8153 out of 25000 queries used. |