답안 #702442

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702442 2023-02-24T05:47:28 Z GusterGoose27 City Mapping (NOI18_citymapping) C++11
86.83 / 100
3 ms 620 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[]) {
	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();
	int f = rng()%n;
	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;
	}
	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) {
		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

citymapping.cpp: In function 'void make_ans(std::vector<int>&, int*, int*, int*)':
citymapping.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for (int i = 0; i < path.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Correct: 2426 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 3170 out of 500000 queries used.
3 Correct 1 ms 468 KB Correct: 5679 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 6236 out of 500000 queries used.
5 Correct 2 ms 468 KB Correct: 5744 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Correct: 2426 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 3170 out of 500000 queries used.
3 Correct 1 ms 468 KB Correct: 5679 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 6236 out of 500000 queries used.
5 Correct 2 ms 468 KB Correct: 5744 out of 500000 queries used.
6 Correct 1 ms 596 KB Correct: 2109 out of 500000 queries used.
7 Correct 2 ms 468 KB Correct: 4631 out of 500000 queries used.
8 Correct 2 ms 468 KB Correct: 5846 out of 500000 queries used.
9 Correct 1 ms 468 KB Correct: 6589 out of 500000 queries used.
10 Correct 2 ms 596 KB Correct: 7108 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Correct: 2124 out of 12000 queries used.
2 Correct 2 ms 596 KB Correct: 2714 out of 12000 queries used.
3 Correct 2 ms 620 KB Correct: 2650 out of 12000 queries used.
4 Correct 2 ms 596 KB Correct: 2801 out of 12000 queries used.
5 Correct 2 ms 596 KB Correct: 2606 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Correct: 2124 out of 12000 queries used.
2 Correct 2 ms 596 KB Correct: 2714 out of 12000 queries used.
3 Correct 2 ms 620 KB Correct: 2650 out of 12000 queries used.
4 Correct 2 ms 596 KB Correct: 2801 out of 12000 queries used.
5 Correct 2 ms 596 KB Correct: 2606 out of 12000 queries used.
6 Correct 2 ms 468 KB Correct: 2200 out of 12000 queries used.
7 Correct 1 ms 596 KB Correct: 3016 out of 12000 queries used.
8 Correct 1 ms 596 KB Correct: 2639 out of 12000 queries used.
9 Correct 1 ms 596 KB Correct: 2648 out of 12000 queries used.
10 Correct 1 ms 596 KB Correct: 2783 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Correct: 2426 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 3170 out of 500000 queries used.
3 Correct 1 ms 468 KB Correct: 5679 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 6236 out of 500000 queries used.
5 Correct 2 ms 468 KB Correct: 5744 out of 500000 queries used.
6 Correct 1 ms 596 KB Correct: 2109 out of 500000 queries used.
7 Correct 2 ms 468 KB Correct: 4631 out of 500000 queries used.
8 Correct 2 ms 468 KB Correct: 5846 out of 500000 queries used.
9 Correct 1 ms 468 KB Correct: 6589 out of 500000 queries used.
10 Correct 2 ms 596 KB Correct: 7108 out of 500000 queries used.
11 Correct 2 ms 596 KB Correct: 2124 out of 12000 queries used.
12 Correct 2 ms 596 KB Correct: 2714 out of 12000 queries used.
13 Correct 2 ms 620 KB Correct: 2650 out of 12000 queries used.
14 Correct 2 ms 596 KB Correct: 2801 out of 12000 queries used.
15 Correct 2 ms 596 KB Correct: 2606 out of 12000 queries used.
16 Correct 2 ms 468 KB Correct: 2200 out of 12000 queries used.
17 Correct 1 ms 596 KB Correct: 3016 out of 12000 queries used.
18 Correct 1 ms 596 KB Correct: 2639 out of 12000 queries used.
19 Correct 1 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: 2440 out of 25000 queries used.
23 Correct 3 ms 468 KB Correct: 5731 out of 25000 queries used.
24 Correct 2 ms 468 KB Correct: 4634 out of 25000 queries used.
25 Correct 3 ms 468 KB Correct: 5781 out of 25000 queries used.
26 Correct 2 ms 468 KB Correct: 6163 out of 25000 queries used.
27 Correct 2 ms 468 KB Correct: 5951 out of 25000 queries used.
28 Correct 2 ms 468 KB Correct: 5796 out of 25000 queries used.
29 Correct 2 ms 468 KB Correct: 6313 out of 25000 queries used.
30 Correct 2 ms 468 KB Correct: 6090 out of 25000 queries used.
31 Correct 2 ms 468 KB Correct: 6294 out of 25000 queries used.
32 Correct 1 ms 596 KB Correct: 3071 out of 25000 queries used.
33 Correct 2 ms 468 KB Correct: 6220 out of 25000 queries used.
34 Correct 1 ms 468 KB Correct: 6329 out of 25000 queries used.
35 Correct 2 ms 468 KB Correct: 6287 out of 25000 queries used.
36 Correct 2 ms 468 KB Correct: 6416 out of 25000 queries used.
37 Correct 2 ms 468 KB Correct: 6698 out of 25000 queries used.
38 Correct 2 ms 468 KB Correct: 6192 out of 25000 queries used.
39 Correct 2 ms 468 KB Correct: 6407 out of 25000 queries used.
40 Correct 2 ms 468 KB Correct: 6319 out of 25000 queries used.
41 Correct 2 ms 468 KB Correct: 6268 out of 25000 queries used.
42 Correct 2 ms 468 KB Correct: 6364 out of 25000 queries used.
43 Correct 2 ms 596 KB Correct: 2126 out of 25000 queries used.
44 Correct 2 ms 468 KB Correct: 6250 out of 25000 queries used.
45 Correct 1 ms 384 KB Correct: 6182 out of 25000 queries used.
46 Correct 2 ms 504 KB Correct: 6227 out of 25000 queries used.
47 Correct 2 ms 468 KB Correct: 6282 out of 25000 queries used.
48 Correct 1 ms 468 KB Correct: 6408 out of 25000 queries used.
49 Correct 2 ms 468 KB Correct: 6337 out of 25000 queries used.
50 Correct 2 ms 468 KB Correct: 6374 out of 25000 queries used.
51 Correct 2 ms 468 KB Correct: 6306 out of 25000 queries used.
52 Correct 2 ms 468 KB Correct: 6345 out of 25000 queries used.
53 Correct 2 ms 468 KB Correct: 6477 out of 25000 queries used.
54 Correct 2 ms 468 KB Correct: 3710 out of 25000 queries used.
55 Correct 2 ms 468 KB Correct: 6300 out of 25000 queries used.
56 Correct 2 ms 408 KB Correct: 6617 out of 25000 queries used.
57 Correct 2 ms 468 KB Correct: 6369 out of 25000 queries used.
58 Correct 3 ms 468 KB Correct: 6422 out of 25000 queries used.
59 Correct 2 ms 468 KB Correct: 6278 out of 25000 queries used.
60 Correct 2 ms 468 KB Correct: 8364 out of 25000 queries used.
61 Correct 2 ms 496 KB Correct: 4863 out of 25000 queries used.
62 Correct 2 ms 468 KB Correct: 5513 out of 25000 queries used.
63 Correct 2 ms 468 KB Correct: 5680 out of 25000 queries used.
64 Correct 2 ms 468 KB Correct: 4480 out of 25000 queries used.
65 Correct 2 ms 468 KB Correct: 6348 out of 25000 queries used.
66 Correct 2 ms 468 KB Correct: 4223 out of 25000 queries used.
67 Correct 2 ms 468 KB Correct: 7732 out of 25000 queries used.
68 Correct 2 ms 468 KB Correct: 3720 out of 25000 queries used.
69 Correct 2 ms 468 KB Correct: 5907 out of 25000 queries used.
70 Correct 2 ms 468 KB Correct: 6057 out of 25000 queries used.