# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
964777 | 2024-04-17T14:12:54 Z | guechotjrhh | City Mapping (NOI18_citymapping) | C++14 | 2 ms | 740 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()); random_device r; default_random_engine e1(r()); uniform_int_distribution<int> ud(0, 1e9 + 7); 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; int piv = ud(e1) % v.size(); while (piv == 0) piv = ud(e1) % v.size(); vector<int> lv; vector<vector<pi>> nv; lv.push_back(0); lv.push_back(piv); nv.push_back({}); nv.push_back({}); int s = 1; for (int i = 1; i < n; i++) { if (i == piv) continue; ll w = get_distance(v[i].x, v[lv[s]].x); ll t = (v[i].y + v[lv[s]].y - w) / 2; if (w == v[lv[s]].y - v[i].y) { lv[s] = i; lv.push_back(piv); nv.push_back({}); s++; } else { 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 func0(vector<pi>& v) {//sorted? int n = v.size(); if (n == 1) return; int piv = ud(e1) % v.size(); while (piv == 0) piv = ud(e1) % v.size(); vector<int> lv; vector<vector<pi>> nv; lv.push_back(0); lv.push_back(piv); nv.push_back({v[0]}); nv.push_back({}); int s = 1; for (int i = 1; i < n; i++) { if (i == piv) continue; ll w = get_distance(v[i].x, v[lv[s]].x); ll t = (v[i].y + v[lv[s]].y - w) / 2; if (w == v[lv[s]].y - v[i].y) { lv[s] = i; lv.push_back(piv); nv.push_back({}); s++; } else { 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()) { if (i > 0) { 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); /*srand(time(0)); int st = rand() % N + 1; ll mx = 0, mi = st; for (int i = 1; i <= N; i++){ if (i == st) continue; ll z = get_distance(st, 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);*/ int mi = ud(e1) % N + 1; 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 }; func0(vc); //for (int i = 0; i < N - 1; i++) cout << a[i] << ' ' << b[i] << ' ' << w[i] << endl; a = NULL; b = NULL; w = NULL; 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 | 1 ms | 600 KB | Correct: 2334 out of 500000 queries used. |
2 | Correct | 1 ms | 604 KB | Correct: 2979 out of 500000 queries used. |
3 | Correct | 1 ms | 604 KB | Correct: 4458 out of 500000 queries used. |
4 | Correct | 2 ms | 604 KB | Correct: 4671 out of 500000 queries used. |
5 | Correct | 1 ms | 604 KB | Correct: 3825 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Correct: 2334 out of 500000 queries used. |
2 | Correct | 1 ms | 604 KB | Correct: 2979 out of 500000 queries used. |
3 | Correct | 1 ms | 604 KB | Correct: 4458 out of 500000 queries used. |
4 | Correct | 2 ms | 604 KB | Correct: 4671 out of 500000 queries used. |
5 | Correct | 1 ms | 604 KB | Correct: 3825 out of 500000 queries used. |
6 | Correct | 1 ms | 604 KB | Correct: 2216 out of 500000 queries used. |
7 | Correct | 1 ms | 604 KB | Correct: 2707 out of 500000 queries used. |
8 | Correct | 1 ms | 604 KB | Correct: 5364 out of 500000 queries used. |
9 | Correct | 1 ms | 604 KB | Correct: 4676 out of 500000 queries used. |
10 | Correct | 1 ms | 604 KB | Correct: 3256 out of 500000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 736 KB | Correct: 2581 out of 12000 queries used. |
2 | Correct | 2 ms | 740 KB | Correct: 2260 out of 12000 queries used. |
3 | Correct | 1 ms | 604 KB | Correct: 2734 out of 12000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 2567 out of 12000 queries used. |
5 | Correct | 2 ms | 604 KB | Correct: 2031 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 736 KB | Correct: 2581 out of 12000 queries used. |
2 | Correct | 2 ms | 740 KB | Correct: 2260 out of 12000 queries used. |
3 | Correct | 1 ms | 604 KB | Correct: 2734 out of 12000 queries used. |
4 | Correct | 1 ms | 604 KB | Correct: 2567 out of 12000 queries used. |
5 | Correct | 2 ms | 604 KB | Correct: 2031 out of 12000 queries used. |
6 | Correct | 1 ms | 604 KB | Correct: 2200 out of 12000 queries used. |
7 | Correct | 1 ms | 484 KB | Correct: 2259 out of 12000 queries used. |
8 | Correct | 1 ms | 600 KB | Correct: 2414 out of 12000 queries used. |
9 | Correct | 1 ms | 604 KB | Correct: 2074 out of 12000 queries used. |
10 | Correct | 1 ms | 600 KB | Correct: 2562 out of 12000 queries used. |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 600 KB | Correct: 2334 out of 500000 queries used. |
2 | Correct | 1 ms | 604 KB | Correct: 2979 out of 500000 queries used. |
3 | Correct | 1 ms | 604 KB | Correct: 4458 out of 500000 queries used. |
4 | Correct | 2 ms | 604 KB | Correct: 4671 out of 500000 queries used. |
5 | Correct | 1 ms | 604 KB | Correct: 3825 out of 500000 queries used. |
6 | Correct | 1 ms | 604 KB | Correct: 2216 out of 500000 queries used. |
7 | Correct | 1 ms | 604 KB | Correct: 2707 out of 500000 queries used. |
8 | Correct | 1 ms | 604 KB | Correct: 5364 out of 500000 queries used. |
9 | Correct | 1 ms | 604 KB | Correct: 4676 out of 500000 queries used. |
10 | Correct | 1 ms | 604 KB | Correct: 3256 out of 500000 queries used. |
11 | Correct | 1 ms | 736 KB | Correct: 2581 out of 12000 queries used. |
12 | Correct | 2 ms | 740 KB | Correct: 2260 out of 12000 queries used. |
13 | Correct | 1 ms | 604 KB | Correct: 2734 out of 12000 queries used. |
14 | Correct | 1 ms | 604 KB | Correct: 2567 out of 12000 queries used. |
15 | Correct | 2 ms | 604 KB | Correct: 2031 out of 12000 queries used. |
16 | Correct | 1 ms | 604 KB | Correct: 2200 out of 12000 queries used. |
17 | Correct | 1 ms | 484 KB | Correct: 2259 out of 12000 queries used. |
18 | Correct | 1 ms | 600 KB | Correct: 2414 out of 12000 queries used. |
19 | Correct | 1 ms | 604 KB | Correct: 2074 out of 12000 queries used. |
20 | Correct | 1 ms | 600 KB | Correct: 2562 out of 12000 queries used. |
21 | Correct | 2 ms | 604 KB | Correct: 2104 out of 25000 queries used. |
22 | Correct | 2 ms | 676 KB | Correct: 4050 out of 25000 queries used. |
23 | Correct | 1 ms | 680 KB | Correct: 2784 out of 25000 queries used. |
24 | Correct | 1 ms | 604 KB | Correct: 3292 out of 25000 queries used. |
25 | Correct | 1 ms | 604 KB | Correct: 4329 out of 25000 queries used. |
26 | Correct | 1 ms | 604 KB | Correct: 4278 out of 25000 queries used. |
27 | Correct | 2 ms | 604 KB | Correct: 4908 out of 25000 queries used. |
28 | Correct | 1 ms | 604 KB | Correct: 5053 out of 25000 queries used. |
29 | Correct | 1 ms | 604 KB | Correct: 4638 out of 25000 queries used. |
30 | Correct | 1 ms | 604 KB | Correct: 5043 out of 25000 queries used. |
31 | Correct | 1 ms | 488 KB | Correct: 5030 out of 25000 queries used. |
32 | Correct | 1 ms | 600 KB | Correct: 2033 out of 25000 queries used. |
33 | Correct | 1 ms | 604 KB | Correct: 4696 out of 25000 queries used. |
34 | Correct | 1 ms | 604 KB | Correct: 4981 out of 25000 queries used. |
35 | Correct | 2 ms | 604 KB | Correct: 4705 out of 25000 queries used. |
36 | Correct | 1 ms | 600 KB | Correct: 4715 out of 25000 queries used. |
37 | Correct | 1 ms | 604 KB | Correct: 4693 out of 25000 queries used. |
38 | Correct | 2 ms | 604 KB | Correct: 4758 out of 25000 queries used. |
39 | Correct | 1 ms | 604 KB | Correct: 4729 out of 25000 queries used. |
40 | Correct | 1 ms | 484 KB | Correct: 4721 out of 25000 queries used. |
41 | Correct | 2 ms | 604 KB | Correct: 5338 out of 25000 queries used. |
42 | Correct | 2 ms | 548 KB | Correct: 4966 out of 25000 queries used. |
43 | Correct | 1 ms | 600 KB | Correct: 2200 out of 25000 queries used. |
44 | Correct | 1 ms | 488 KB | Correct: 4713 out of 25000 queries used. |
45 | Correct | 2 ms | 604 KB | Correct: 4679 out of 25000 queries used. |
46 | Correct | 2 ms | 600 KB | Correct: 4709 out of 25000 queries used. |
47 | Correct | 1 ms | 604 KB | Correct: 5025 out of 25000 queries used. |
48 | Correct | 2 ms | 604 KB | Correct: 4999 out of 25000 queries used. |
49 | Correct | 2 ms | 604 KB | Correct: 4957 out of 25000 queries used. |
50 | Correct | 1 ms | 684 KB | Correct: 5382 out of 25000 queries used. |
51 | Correct | 2 ms | 604 KB | Correct: 4994 out of 25000 queries used. |
52 | Correct | 2 ms | 604 KB | Correct: 4748 out of 25000 queries used. |
53 | Correct | 1 ms | 604 KB | Correct: 4992 out of 25000 queries used. |
54 | Correct | 2 ms | 604 KB | Correct: 2530 out of 25000 queries used. |
55 | Correct | 2 ms | 680 KB | Correct: 5465 out of 25000 queries used. |
56 | Correct | 1 ms | 604 KB | Correct: 4670 out of 25000 queries used. |
57 | Correct | 1 ms | 604 KB | Correct: 4741 out of 25000 queries used. |
58 | Correct | 2 ms | 604 KB | Correct: 5583 out of 25000 queries used. |
59 | Correct | 2 ms | 604 KB | Correct: 4715 out of 25000 queries used. |
60 | Correct | 1 ms | 604 KB | Correct: 3073 out of 25000 queries used. |
61 | Correct | 1 ms | 532 KB | Correct: 3293 out of 25000 queries used. |
62 | Correct | 2 ms | 488 KB | Correct: 3491 out of 25000 queries used. |
63 | Correct | 2 ms | 604 KB | Correct: 3703 out of 25000 queries used. |
64 | Correct | 1 ms | 604 KB | Correct: 4020 out of 25000 queries used. |
65 | Correct | 1 ms | 600 KB | Correct: 2909 out of 25000 queries used. |
66 | Correct | 2 ms | 600 KB | Correct: 3364 out of 25000 queries used. |
67 | Correct | 2 ms | 604 KB | Correct: 2745 out of 25000 queries used. |
68 | Correct | 1 ms | 600 KB | Correct: 2449 out of 25000 queries used. |
69 | Correct | 2 ms | 604 KB | Correct: 2589 out of 25000 queries used. |
70 | Correct | 1 ms | 604 KB | Correct: 2913 out of 25000 queries used. |