# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964014 | 2024-04-16T07:50:25 Z | guechotjrhh | City Mapping (NOI18_citymapping) | C++14 | 10 ms | 2908 KB |
#include "citymapping.h" #include<vector> #include<algorithm> #include<random> #include<iostream> using namespace std; #define ll long long #define pi pair<ll,ll> #define x first #define y second random_device rd; mt19937 g(rd()); int* a, * b, * w; int p = 0; void rec(vector<int>& v) { int n = v.size(); if (n == 1) return; shuffle(v.begin(), v.end(), g); int u1 = v[0], u2 = v[1]; vector<ll> d1(n, 0), d2(n, 0); vector<int> v1, v2; int t1 = 1, t2 = 0; for (int i = 0; i < n; i++) { if (v[i] != u1) d1[i] = get_distance(v[i], u1); if (v[i] != u2) d2[i] = get_distance(v[i], u2); if (d1[i] < d2[i]) { v1.push_back(v[i]); if (d2[i] < d2[t2]) t2 = i; } else { v2.push_back(v[i]); if (d1[i] < d1[t1]) t1 = i; } } a[p] = v[t1]; b[p] = v[t2]; w[p] = d1[t1] - d1[t2]; p++; rec(v1); rec(v2); } void func(vector<pi> &v) {//sorted? //cout << "v:\n"; //for (pi p : v) {cout << p.x << ' ' << p.y << endl;} int n = v.size(); if (n == 1) return; vector<int> lv; vector<vector<pi>> nv; lv.push_back(0); lv.push_back(1); nv.push_back({}); nv.push_back({}); int s = 1; for (int i = 2; i < n; i++) { ll w = get_distance(v[i].x, v[lv[s]].x); ll t = (v[i].y + v[lv[s]].y - w) / 2; int j = 0; while (t > v[lv[j]].y) j++; if (j == s) { nv.push_back({}); lv.push_back(i); s++; } else { nv[j].push_back(v[i]); } } for (int i = 1; i <= s; i++) { a[p] = v[lv[i]].x; b[p] = v[lv[i - 1]].x; w[p] = v[lv[i]].y - v[lv[i - 1]].y; p++; } for (int i = 0; i <= s; i++) { if (nv[i].size()) { a[p] = v[lv[i]].x; b[p] = nv[i][0].x; w[p] = nv[i][0].y - v[lv[i]].y; p++; ll o = nv[i][0].y; for (int j = 0; j < nv[i].size(); j++) nv[i][j].y -= o; func(nv[i]); } } } void find_roads(int N, int Q, int A[], int B[], int W[]) { a = A; b = B; w = W; /*ll u = 0, mi = 1; for (int i = 2; i <= N; i++) { ll x = get_distance(1, i); if (x > u) { u = x; mi = i; } } vector<pi> vec; for (int i = 1; i <= N; i++) { if (i != mi) vec.push_back({ get_distance(mi,i),i }); } sort(vec.begin(), vec.end()); A[0] = mi; B[0] = vec[0].y; W[0] = vec[0].x; for (int i = 1; i < N-1; i++) { A[i] = vec[i].y; B[i] = vec[i - 1].y; W[i] = vec[i].x - vec[i - 1].x; }*/ //vector<int> v(N); for (int i = 1; i <= N; i++) v[i - 1] = i; //rec(v); ll mx = 0, mi = 1; for (int i = 2; i <= N; i++){ ll z = get_distance(1, i); if (z > mx) { mx = z; mi = i; } } vector<pi> vu = { { 0,mi } }; for (int i = 1; i <= N; i++) if (i != mi) vu.push_back({ get_distance(mi,i), i }); sort(vu.begin(), vu.end()); vector<pi> vc(N); for (int i = 0; i < N; i++) vc[i] = { vu[i].y,vu[i].x }; func(vc); //for (int i = 0; i < N - 1; i++) cout << a[i] << ' ' << b[i] << ' ' << w[i] << endl; return; } /* 5 500000 1 1 4 8 4 2 1 4 3 7 3 5 3 */
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 600 KB | Correct: 2993 out of 500000 queries used. |
2 | Correct | 10 ms | 2908 KB | Correct: 122756 out of 500000 queries used. |
3 | Correct | 2 ms | 736 KB | Correct: 12108 out of 500000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 10209 out of 500000 queries used. |
5 | Correct | 2 ms | 604 KB | Correct: 6267 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 600 KB | Correct: 2993 out of 500000 queries used. |
2 | Correct | 10 ms | 2908 KB | Correct: 122756 out of 500000 queries used. |
3 | Correct | 2 ms | 736 KB | Correct: 12108 out of 500000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 10209 out of 500000 queries used. |
5 | Correct | 2 ms | 604 KB | Correct: 6267 out of 500000 queries used. |
6 | Correct | 2 ms | 600 KB | Correct: 2984 out of 500000 queries used. |
7 | Correct | 1 ms | 604 KB | Correct: 3983 out of 500000 queries used. |
8 | Correct | 2 ms | 604 KB | Correct: 15597 out of 500000 queries used. |
9 | Correct | 2 ms | 604 KB | Correct: 9264 out of 500000 queries used. |
10 | Correct | 1 ms | 480 KB | Correct: 6277 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Correct: 2969 out of 12000 queries used. |
2 | Correct | 1 ms | 600 KB | Correct: 2975 out of 12000 queries used. |
3 | Correct | 3 ms | 604 KB | Correct: 2996 out of 12000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 2975 out of 12000 queries used. |
5 | Correct | 1 ms | 604 KB | Correct: 2969 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Correct: 2969 out of 12000 queries used. |
2 | Correct | 1 ms | 600 KB | Correct: 2975 out of 12000 queries used. |
3 | Correct | 3 ms | 604 KB | Correct: 2996 out of 12000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 2975 out of 12000 queries used. |
5 | Correct | 1 ms | 604 KB | Correct: 2969 out of 12000 queries used. |
6 | Correct | 1 ms | 604 KB | Correct: 2990 out of 12000 queries used. |
7 | Correct | 2 ms | 604 KB | Correct: 2984 out of 12000 queries used. |
8 | Correct | 1 ms | 604 KB | Correct: 2996 out of 12000 queries used. |
9 | Correct | 1 ms | 604 KB | Correct: 2987 out of 12000 queries used. |
10 | Correct | 2 ms | 600 KB | Correct: 2978 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 600 KB | Correct: 2993 out of 500000 queries used. |
2 | Correct | 10 ms | 2908 KB | Correct: 122756 out of 500000 queries used. |
3 | Correct | 2 ms | 736 KB | Correct: 12108 out of 500000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 10209 out of 500000 queries used. |
5 | Correct | 2 ms | 604 KB | Correct: 6267 out of 500000 queries used. |
6 | Correct | 2 ms | 600 KB | Correct: 2984 out of 500000 queries used. |
7 | Correct | 1 ms | 604 KB | Correct: 3983 out of 500000 queries used. |
8 | Correct | 2 ms | 604 KB | Correct: 15597 out of 500000 queries used. |
9 | Correct | 2 ms | 604 KB | Correct: 9264 out of 500000 queries used. |
10 | Correct | 1 ms | 480 KB | Correct: 6277 out of 500000 queries used. |
11 | Correct | 1 ms | 604 KB | Correct: 2969 out of 12000 queries used. |
12 | Correct | 1 ms | 600 KB | Correct: 2975 out of 12000 queries used. |
13 | Correct | 3 ms | 604 KB | Correct: 2996 out of 12000 queries used. |
14 | Correct | 1 ms | 604 KB | Correct: 2975 out of 12000 queries used. |
15 | Correct | 1 ms | 604 KB | Correct: 2969 out of 12000 queries used. |
16 | Correct | 1 ms | 604 KB | Correct: 2990 out of 12000 queries used. |
17 | Correct | 2 ms | 604 KB | Correct: 2984 out of 12000 queries used. |
18 | Correct | 1 ms | 604 KB | Correct: 2996 out of 12000 queries used. |
19 | Correct | 1 ms | 604 KB | Correct: 2987 out of 12000 queries used. |
20 | Correct | 2 ms | 600 KB | Correct: 2978 out of 12000 queries used. |
21 | Correct | 2 ms | 604 KB | Correct: 2984 out of 25000 queries used. |
22 | Correct | 1 ms | 600 KB | Correct: 2993 out of 25000 queries used. |
23 | Correct | 1 ms | 676 KB | Correct: 2975 out of 25000 queries used. |
24 | Correct | 1 ms | 604 KB | Correct: 2972 out of 25000 queries used. |
25 | Correct | 2 ms | 796 KB | Correct: 12469 out of 25000 queries used. |
26 | Correct | 2 ms | 600 KB | Correct: 13726 out of 25000 queries used. |
27 | Correct | 2 ms | 800 KB | Correct: 13233 out of 25000 queries used. |
28 | Correct | 2 ms | 600 KB | Correct: 11353 out of 25000 queries used. |
29 | Correct | 2 ms | 604 KB | Correct: 11018 out of 25000 queries used. |
30 | Correct | 2 ms | 604 KB | Correct: 13078 out of 25000 queries used. |
31 | Correct | 3 ms | 604 KB | Correct: 11630 out of 25000 queries used. |
32 | Correct | 2 ms | 604 KB | Correct: 2981 out of 25000 queries used. |
33 | Correct | 2 ms | 604 KB | Correct: 11385 out of 25000 queries used. |
34 | Correct | 2 ms | 600 KB | Correct: 11305 out of 25000 queries used. |
35 | Correct | 2 ms | 604 KB | Correct: 10905 out of 25000 queries used. |
36 | Correct | 2 ms | 604 KB | Correct: 11163 out of 25000 queries used. |
37 | Correct | 2 ms | 604 KB | Correct: 10966 out of 25000 queries used. |
38 | Correct | 2 ms | 608 KB | Correct: 11078 out of 25000 queries used. |
39 | Correct | 2 ms | 536 KB | Correct: 9279 out of 25000 queries used. |
40 | Correct | 2 ms | 604 KB | Correct: 11495 out of 25000 queries used. |
41 | Correct | 3 ms | 604 KB | Correct: 12159 out of 25000 queries used. |
42 | Correct | 2 ms | 604 KB | Correct: 11655 out of 25000 queries used. |
43 | Correct | 2 ms | 604 KB | Correct: 2990 out of 25000 queries used. |
44 | Correct | 2 ms | 600 KB | Correct: 11279 out of 25000 queries used. |
45 | Correct | 2 ms | 604 KB | Correct: 11217 out of 25000 queries used. |
46 | Correct | 2 ms | 740 KB | Correct: 10754 out of 25000 queries used. |
47 | Correct | 2 ms | 604 KB | Correct: 12046 out of 25000 queries used. |
48 | Correct | 2 ms | 600 KB | Correct: 11793 out of 25000 queries used. |
49 | Correct | 2 ms | 604 KB | Correct: 11545 out of 25000 queries used. |
50 | Correct | 3 ms | 604 KB | Correct: 12242 out of 25000 queries used. |
51 | Correct | 2 ms | 604 KB | Correct: 9909 out of 25000 queries used. |
52 | Correct | 2 ms | 604 KB | Correct: 11479 out of 25000 queries used. |
53 | Correct | 2 ms | 604 KB | Correct: 10295 out of 25000 queries used. |
54 | Correct | 2 ms | 864 KB | Correct: 2996 out of 25000 queries used. |
55 | Correct | 2 ms | 600 KB | Correct: 9653 out of 25000 queries used. |
56 | Correct | 2 ms | 604 KB | Correct: 10930 out of 25000 queries used. |
57 | Correct | 3 ms | 600 KB | Correct: 11373 out of 25000 queries used. |
58 | Correct | 2 ms | 604 KB | Correct: 9985 out of 25000 queries used. |
59 | Correct | 2 ms | 732 KB | Correct: 10146 out of 25000 queries used. |
60 | Correct | 2 ms | 776 KB | Correct: 10891 out of 25000 queries used. |
61 | Correct | 1 ms | 600 KB | Correct: 6513 out of 25000 queries used. |
62 | Correct | 2 ms | 600 KB | Correct: 7711 out of 25000 queries used. |
63 | Correct | 2 ms | 532 KB | Correct: 5980 out of 25000 queries used. |
64 | Correct | 2 ms | 604 KB | Correct: 7932 out of 25000 queries used. |
65 | Correct | 1 ms | 604 KB | Correct: 2969 out of 25000 queries used. |
66 | Correct | 2 ms | 604 KB | Correct: 6494 out of 25000 queries used. |
67 | Correct | 2 ms | 600 KB | Correct: 2975 out of 25000 queries used. |
68 | Correct | 1 ms | 600 KB | Correct: 2972 out of 25000 queries used. |
69 | Correct | 2 ms | 604 KB | Correct: 3979 out of 25000 queries used. |
70 | Correct | 2 ms | 604 KB | Correct: 2978 out of 25000 queries used. |