Submission #1024903

# Submission time Handle Problem Language Result Execution time Memory
1024903 2024-07-16T12:04:47 Z thinknoexit City Mapping (NOI18_citymapping) C++17
63.19 / 100
5 ms 8796 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1010;
mt19937 rnd(time(NULL));
int n;
ll dis[N][N];
int A[N], B[N], W[N], tot;
ll d(int i, int j) {
	if (i == j) return 0;
	if (!dis[i][j]) return dis[i][j] = dis[j][i] = get_distance(i, j);
	return dis[i][j];
}
void play(vector<int>& v, int U, int V) {
	int m = v.size();
	if (m == 1) return;
	ll all = d(U, V);
	vector<pair<ll, int>> in, rem;
	for (auto& x : v) {
		if (d(U, x) + d(x, V) == all) in.push_back({ d(V, x), x });
		else {
			ll extra = (d(U, x) + d(x, V) - all) / 2;
			rem.push_back({ d(V, x) - extra, x });
		}
	}
	sort(in.begin(), in.end());
	sort(rem.begin(), rem.end());
	vector<vector<int>> r;
	vector<int> p2, p3;
	int p = 0;
	for (int i = 1;i < (int)in.size();i++) {
		A[tot] = in[i - 1].second;
		B[tot] = in[i].second;
		W[tot] = in[i].first - in[i - 1].first;
		tot++;
		vector<int> nw;
		ll mn = LLONG_MAX;
		int idx = 0;
		while (p < (int)rem.size() && rem[p].first == in[i].first) {
			int vl = rem[p].second;
			ll extra = (d(U, vl) + d(vl, V) - all) / 2;
			if (extra < mn) {
				mn = extra;
				idx = vl;
			}
			nw.push_back(vl);
			p++;
		}
		if (!nw.empty()) {
			A[tot] = idx;
			B[tot] = in[i].second;
			W[tot] = mn;
			tot++;
			ll mx = -1;
			int idx2 = 0;
			for (auto& x : nw) {
				dis[idx][x] = dis[x][idx] = d(V, x) - mn - in[i].first;
				if (dis[idx][x] > mx) {
					mx = dis[idx][x];
					idx2 = x;
				}
			}
			r.push_back(nw);
			p2.push_back(idx);
			p3.push_back(idx2);
		}
	}
	for (int i = 0;i < (int)r.size();i++) {
		play(r[i], p2[i], p3[i]);
	}
}
void find_roads(int NN, int Q, int A[], int B[], int W[]) {
	n = NN;
	vector<int> init(n);
	int rt = rnd() % n + 1;
	iota(init.begin(), init.end(), 1);
	int leaf = 0, leaf2 = 0;
	ll mx = -1;
	for (int i = 1;i <= n;i++) {
		if (d(rt, i) > mx) {
			mx = d(rt, i);
			leaf = i;
		}
	}
	sort(init.begin(), init.end(), [&](int a, int b) {
		return d(rt, a) < d(rt, b);
		});
	play(init, init[n - 2], init[n - 1]);
	for (int i = 0;i < n - 1;i++) {
		A[i] = ::A[i];
		B[i] = ::B[i];
		W[i] = ::W[i];
		//cout << A[i] << ' ' << B[i] << ' ' << W[i] << '\n';
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:78:6: warning: variable 'leaf' set but not used [-Wunused-but-set-variable]
   78 |  int leaf = 0, leaf2 = 0;
      |      ^~~~
citymapping.cpp:78:16: warning: unused variable 'leaf2' [-Wunused-variable]
   78 |  int leaf = 0, leaf2 = 0;
      |                ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Correct: 3985 out of 500000 queries used.
2 Correct 3 ms 8540 KB Correct: 3988 out of 500000 queries used.
3 Correct 3 ms 8284 KB Correct: 5942 out of 500000 queries used.
4 Correct 3 ms 8284 KB Correct: 6459 out of 500000 queries used.
5 Correct 3 ms 8732 KB Correct: 12544 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Correct: 3985 out of 500000 queries used.
2 Correct 3 ms 8540 KB Correct: 3988 out of 500000 queries used.
3 Correct 3 ms 8284 KB Correct: 5942 out of 500000 queries used.
4 Correct 3 ms 8284 KB Correct: 6459 out of 500000 queries used.
5 Correct 3 ms 8732 KB Correct: 12544 out of 500000 queries used.
6 Correct 3 ms 8284 KB Correct: 3973 out of 500000 queries used.
7 Correct 3 ms 8796 KB Correct: 16342 out of 500000 queries used.
8 Correct 2 ms 8540 KB Correct: 5746 out of 500000 queries used.
9 Correct 3 ms 8540 KB Correct: 6521 out of 500000 queries used.
10 Correct 3 ms 8540 KB Correct: 6569 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Correct: 3953 out of 12000 queries used.
2 Correct 3 ms 8028 KB Correct: 3961 out of 12000 queries used.
3 Correct 2 ms 8416 KB Correct: 3989 out of 12000 queries used.
4 Correct 3 ms 8284 KB Correct: 3961 out of 12000 queries used.
5 Correct 2 ms 8284 KB Correct: 3953 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Correct: 3953 out of 12000 queries used.
2 Correct 3 ms 8028 KB Correct: 3961 out of 12000 queries used.
3 Correct 2 ms 8416 KB Correct: 3989 out of 12000 queries used.
4 Correct 3 ms 8284 KB Correct: 3961 out of 12000 queries used.
5 Correct 2 ms 8284 KB Correct: 3953 out of 12000 queries used.
6 Correct 2 ms 8536 KB Correct: 3981 out of 12000 queries used.
7 Correct 2 ms 8540 KB Correct: 3973 out of 12000 queries used.
8 Correct 2 ms 8284 KB Correct: 3989 out of 12000 queries used.
9 Correct 3 ms 8540 KB Correct: 3977 out of 12000 queries used.
10 Correct 3 ms 8540 KB Correct: 3965 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Correct: 3985 out of 500000 queries used.
2 Correct 3 ms 8540 KB Correct: 3988 out of 500000 queries used.
3 Correct 3 ms 8284 KB Correct: 5942 out of 500000 queries used.
4 Correct 3 ms 8284 KB Correct: 6459 out of 500000 queries used.
5 Correct 3 ms 8732 KB Correct: 12544 out of 500000 queries used.
6 Correct 3 ms 8284 KB Correct: 3973 out of 500000 queries used.
7 Correct 3 ms 8796 KB Correct: 16342 out of 500000 queries used.
8 Correct 2 ms 8540 KB Correct: 5746 out of 500000 queries used.
9 Correct 3 ms 8540 KB Correct: 6521 out of 500000 queries used.
10 Correct 3 ms 8540 KB Correct: 6569 out of 500000 queries used.
11 Correct 3 ms 8540 KB Correct: 3953 out of 12000 queries used.
12 Correct 3 ms 8028 KB Correct: 3961 out of 12000 queries used.
13 Correct 2 ms 8416 KB Correct: 3989 out of 12000 queries used.
14 Correct 3 ms 8284 KB Correct: 3961 out of 12000 queries used.
15 Correct 2 ms 8284 KB Correct: 3953 out of 12000 queries used.
16 Correct 2 ms 8536 KB Correct: 3981 out of 12000 queries used.
17 Correct 2 ms 8540 KB Correct: 3973 out of 12000 queries used.
18 Correct 2 ms 8284 KB Correct: 3989 out of 12000 queries used.
19 Correct 3 ms 8540 KB Correct: 3977 out of 12000 queries used.
20 Correct 3 ms 8540 KB Correct: 3965 out of 12000 queries used.
21 Correct 2 ms 8540 KB Correct: 3973 out of 25000 queries used.
22 Correct 3 ms 8540 KB Correct: 6349 out of 25000 queries used.
23 Correct 3 ms 8540 KB Correct: 4000 out of 25000 queries used.
24 Correct 3 ms 8496 KB Correct: 5301 out of 25000 queries used.
25 Correct 3 ms 8344 KB Correct: 5876 out of 25000 queries used.
26 Correct 3 ms 8280 KB Correct: 5777 out of 25000 queries used.
27 Correct 3 ms 8284 KB Correct: 5925 out of 25000 queries used.
28 Correct 3 ms 8540 KB Correct: 6058 out of 25000 queries used.
29 Correct 3 ms 8536 KB Correct: 5488 out of 25000 queries used.
30 Correct 4 ms 8284 KB Correct: 6522 out of 25000 queries used.
31 Correct 3 ms 8540 KB Correct: 6700 out of 25000 queries used.
32 Correct 2 ms 7772 KB Correct: 3969 out of 25000 queries used.
33 Correct 4 ms 8280 KB Correct: 6666 out of 25000 queries used.
34 Correct 3 ms 8520 KB Correct: 6702 out of 25000 queries used.
35 Correct 2 ms 8284 KB Correct: 5947 out of 25000 queries used.
36 Correct 3 ms 8284 KB Correct: 6644 out of 25000 queries used.
37 Correct 3 ms 8284 KB Correct: 5911 out of 25000 queries used.
38 Correct 3 ms 8352 KB Correct: 6701 out of 25000 queries used.
39 Correct 3 ms 8540 KB Correct: 6678 out of 25000 queries used.
40 Correct 3 ms 8284 KB Correct: 5977 out of 25000 queries used.
41 Correct 3 ms 8540 KB Correct: 6682 out of 25000 queries used.
42 Correct 3 ms 8540 KB Correct: 6692 out of 25000 queries used.
43 Correct 3 ms 8540 KB Correct: 3981 out of 25000 queries used.
44 Correct 3 ms 8284 KB Correct: 5920 out of 25000 queries used.
45 Correct 3 ms 8284 KB Correct: 6647 out of 25000 queries used.
46 Correct 2 ms 8284 KB Correct: 5855 out of 25000 queries used.
47 Correct 3 ms 8540 KB Correct: 6639 out of 25000 queries used.
48 Correct 3 ms 8280 KB Correct: 6708 out of 25000 queries used.
49 Correct 3 ms 8284 KB Correct: 5717 out of 25000 queries used.
50 Correct 3 ms 8540 KB Correct: 6690 out of 25000 queries used.
51 Correct 3 ms 8284 KB Correct: 6704 out of 25000 queries used.
52 Correct 4 ms 8540 KB Correct: 6676 out of 25000 queries used.
53 Correct 4 ms 8540 KB Correct: 6562 out of 25000 queries used.
54 Correct 5 ms 8684 KB Correct: 16467 out of 25000 queries used.
55 Correct 3 ms 8284 KB Correct: 6677 out of 25000 queries used.
56 Correct 3 ms 8284 KB Correct: 5914 out of 25000 queries used.
57 Correct 4 ms 8540 KB Correct: 5974 out of 25000 queries used.
58 Correct 3 ms 8284 KB Correct: 6618 out of 25000 queries used.
59 Correct 3 ms 8284 KB Correct: 6639 out of 25000 queries used.
60 Correct 3 ms 8540 KB Correct: 6775 out of 25000 queries used.
61 Correct 3 ms 8284 KB Correct: 7697 out of 25000 queries used.
62 Correct 3 ms 8540 KB Correct: 6923 out of 25000 queries used.
63 Correct 3 ms 8540 KB Correct: 6991 out of 25000 queries used.
64 Correct 3 ms 8536 KB Correct: 6964 out of 25000 queries used.
65 Correct 3 ms 8540 KB Correct: 8376 out of 25000 queries used.
66 Correct 3 ms 8400 KB Correct: 7556 out of 25000 queries used.
67 Correct 3 ms 8540 KB Correct: 4160 out of 25000 queries used.
68 Correct 4 ms 8796 KB Correct: 16950 out of 25000 queries used.
69 Correct 4 ms 8540 KB Correct: 11846 out of 25000 queries used.
70 Correct 5 ms 8540 KB Correct: 12837 out of 25000 queries used.