# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702451 | 2023-02-24T05:57:08 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 | 596 KB | Correct: 2426 out of 500000 queries used. |
2 | Correct | 2 ms | 468 KB | Correct: 2977 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 6140 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 7315 out of 500000 queries used. |
5 | Correct | 2 ms | 468 KB | Correct: 6668 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Correct: 2426 out of 500000 queries used. |
2 | Correct | 2 ms | 468 KB | Correct: 2977 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 6140 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 7315 out of 500000 queries used. |
5 | Correct | 2 ms | 468 KB | Correct: 6668 out of 500000 queries used. |
6 | Correct | 2 ms | 596 KB | Correct: 2109 out of 500000 queries used. |
7 | Correct | 2 ms | 468 KB | Correct: 5715 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 6453 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 7982 out of 500000 queries used. |
10 | Correct | 2 ms | 468 KB | Correct: 7241 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Correct: 2124 out of 12000 queries used. |
2 | Correct | 1 ms | 596 KB | Correct: 2714 out of 12000 queries used. |
3 | Correct | 2 ms | 596 KB | Correct: 2650 out of 12000 queries used. |
4 | Correct | 1 ms | 596 KB | Correct: 2801 out of 12000 queries used. |
5 | Correct | 1 ms | 596 KB | Correct: 2606 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 596 KB | Correct: 2124 out of 12000 queries used. |
2 | Correct | 1 ms | 596 KB | Correct: 2714 out of 12000 queries used. |
3 | Correct | 2 ms | 596 KB | Correct: 2650 out of 12000 queries used. |
4 | Correct | 1 ms | 596 KB | Correct: 2801 out of 12000 queries used. |
5 | Correct | 1 ms | 596 KB | Correct: 2606 out of 12000 queries used. |
6 | Correct | 2 ms | 596 KB | Correct: 2200 out of 12000 queries used. |
7 | Correct | 2 ms | 508 KB | Correct: 3016 out of 12000 queries used. |
8 | Correct | 1 ms | 596 KB | Correct: 2639 out of 12000 queries used. |
9 | Correct | 2 ms | 596 KB | Correct: 2648 out of 12000 queries used. |
10 | Correct | 1 ms | 596 KB | Correct: 2783 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 596 KB | Correct: 2426 out of 500000 queries used. |
2 | Correct | 2 ms | 468 KB | Correct: 2977 out of 500000 queries used. |
3 | Correct | 2 ms | 468 KB | Correct: 6140 out of 500000 queries used. |
4 | Correct | 2 ms | 468 KB | Correct: 7315 out of 500000 queries used. |
5 | Correct | 2 ms | 468 KB | Correct: 6668 out of 500000 queries used. |
6 | Correct | 2 ms | 596 KB | Correct: 2109 out of 500000 queries used. |
7 | Correct | 2 ms | 468 KB | Correct: 5715 out of 500000 queries used. |
8 | Correct | 2 ms | 468 KB | Correct: 6453 out of 500000 queries used. |
9 | Correct | 2 ms | 468 KB | Correct: 7982 out of 500000 queries used. |
10 | Correct | 2 ms | 468 KB | Correct: 7241 out of 500000 queries used. |
11 | Correct | 1 ms | 596 KB | Correct: 2124 out of 12000 queries used. |
12 | Correct | 1 ms | 596 KB | Correct: 2714 out of 12000 queries used. |
13 | Correct | 2 ms | 596 KB | Correct: 2650 out of 12000 queries used. |
14 | Correct | 1 ms | 596 KB | Correct: 2801 out of 12000 queries used. |
15 | Correct | 1 ms | 596 KB | Correct: 2606 out of 12000 queries used. |
16 | Correct | 2 ms | 596 KB | Correct: 2200 out of 12000 queries used. |
17 | Correct | 2 ms | 508 KB | Correct: 3016 out of 12000 queries used. |
18 | Correct | 1 ms | 596 KB | Correct: 2639 out of 12000 queries used. |
19 | Correct | 2 ms | 596 KB | Correct: 2648 out of 12000 queries used. |
20 | Correct | 1 ms | 596 KB | Correct: 2783 out of 12000 queries used. |
21 | Correct | 1 ms | 596 KB | Correct: 2564 out of 25000 queries used. |
22 | Correct | 1 ms | 468 KB | Correct: 2499 out of 25000 queries used. |
23 | Correct | 2 ms | 468 KB | Correct: 5266 out of 25000 queries used. |
24 | Correct | 2 ms | 468 KB | Correct: 4619 out of 25000 queries used. |
25 | Correct | 2 ms | 468 KB | Correct: 6450 out of 25000 queries used. |
26 | Correct | 2 ms | 468 KB | Correct: 6667 out of 25000 queries used. |
27 | Correct | 2 ms | 468 KB | Correct: 6668 out of 25000 queries used. |
28 | Correct | 1 ms | 468 KB | Correct: 6503 out of 25000 queries used. |
29 | Correct | 2 ms | 468 KB | Correct: 6917 out of 25000 queries used. |
30 | Correct | 2 ms | 504 KB | Correct: 6527 out of 25000 queries used. |
31 | Correct | 2 ms | 468 KB | Correct: 7424 out of 25000 queries used. |
32 | Correct | 2 ms | 596 KB | Correct: 3071 out of 25000 queries used. |
33 | Correct | 2 ms | 468 KB | Correct: 7377 out of 25000 queries used. |
34 | Correct | 2 ms | 468 KB | Correct: 7428 out of 25000 queries used. |
35 | Correct | 2 ms | 468 KB | Correct: 7473 out of 25000 queries used. |
36 | Correct | 2 ms | 468 KB | Correct: 7400 out of 25000 queries used. |
37 | Correct | 2 ms | 468 KB | Correct: 8004 out of 25000 queries used. |
38 | Correct | 2 ms | 468 KB | Correct: 7367 out of 25000 queries used. |
39 | Correct | 1 ms | 468 KB | Correct: 7456 out of 25000 queries used. |
40 | Correct | 2 ms | 468 KB | Correct: 7535 out of 25000 queries used. |
41 | Correct | 2 ms | 468 KB | Correct: 7525 out of 25000 queries used. |
42 | Correct | 2 ms | 468 KB | Correct: 7481 out of 25000 queries used. |
43 | Correct | 1 ms | 596 KB | Correct: 2126 out of 25000 queries used. |
44 | Correct | 2 ms | 468 KB | Correct: 7484 out of 25000 queries used. |
45 | Correct | 2 ms | 468 KB | Correct: 7462 out of 25000 queries used. |
46 | Correct | 2 ms | 468 KB | Correct: 7372 out of 25000 queries used. |
47 | Correct | 2 ms | 468 KB | Correct: 7504 out of 25000 queries used. |
48 | Correct | 2 ms | 468 KB | Correct: 7489 out of 25000 queries used. |
49 | Correct | 2 ms | 468 KB | Correct: 7503 out of 25000 queries used. |
50 | Correct | 2 ms | 468 KB | Correct: 7418 out of 25000 queries used. |
51 | Correct | 2 ms | 468 KB | Correct: 7540 out of 25000 queries used. |
52 | Correct | 2 ms | 468 KB | Correct: 7437 out of 25000 queries used. |
53 | Correct | 2 ms | 468 KB | Correct: 7551 out of 25000 queries used. |
54 | Correct | 2 ms | 468 KB | Correct: 4427 out of 25000 queries used. |
55 | Correct | 2 ms | 468 KB | Correct: 7503 out of 25000 queries used. |
56 | Correct | 1 ms | 468 KB | Correct: 7963 out of 25000 queries used. |
57 | Correct | 2 ms | 468 KB | Correct: 7557 out of 25000 queries used. |
58 | Correct | 3 ms | 468 KB | Correct: 7407 out of 25000 queries used. |
59 | Correct | 2 ms | 468 KB | Correct: 7394 out of 25000 queries used. |
60 | Correct | 2 ms | 468 KB | Correct: 9735 out of 25000 queries used. |
61 | Correct | 2 ms | 468 KB | Correct: 5167 out of 25000 queries used. |
62 | Correct | 2 ms | 468 KB | Correct: 7542 out of 25000 queries used. |
63 | Correct | 2 ms | 468 KB | Correct: 9407 out of 25000 queries used. |
64 | Correct | 2 ms | 468 KB | Correct: 4569 out of 25000 queries used. |
65 | Correct | 2 ms | 596 KB | Correct: 12189 out of 25000 queries used. |
66 | Correct | 1 ms | 468 KB | Correct: 3805 out of 25000 queries used. |
67 | Correct | 1 ms | 468 KB | Correct: 4267 out of 25000 queries used. |
68 | Correct | 2 ms | 468 KB | Correct: 5652 out of 25000 queries used. |
69 | Correct | 2 ms | 468 KB | Correct: 6869 out of 25000 queries used. |
70 | Correct | 2 ms | 596 KB | Correct: 14445 out of 25000 queries used. |