답안 #702444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702444 2023-02-24T05:52:47 Z GusterGoose27 City Mapping (NOI18_citymapping) C++11
57 / 100
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[]) {
	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 = 0;
	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[1][f] = dist[0][mx];
	for (int i = 0; i < n; i++) {
		if (i == f || i == mx) continue;
		dist[1][i] = get_distance(vals[i], vals[mx]);
		if (dist[1][i] > dist[1][f]) f = i;
	}
	dist[0][mx] = dist[1][f];
	for (int i = 0; i < n; i++) {
		if (i == f || i == mx) continue;
		dist[0][i] = get_distance(vals[i], vals[f]);
	}
	dist[0][f] = 0;
	dist[1][mx] = 0;
	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:78: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]
   78 |  for (int i = 0; i < path.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Correct: 2992 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 2995 out of 500000 queries used.
3 Correct 2 ms 468 KB Correct: 7790 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 8918 out of 500000 queries used.
5 Correct 3 ms 596 KB Correct: 16553 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Correct: 2992 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 2995 out of 500000 queries used.
3 Correct 2 ms 468 KB Correct: 7790 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 8918 out of 500000 queries used.
5 Correct 3 ms 596 KB Correct: 16553 out of 500000 queries used.
6 Correct 2 ms 596 KB Correct: 2983 out of 500000 queries used.
7 Correct 3 ms 596 KB Correct: 29223 out of 500000 queries used.
8 Correct 2 ms 468 KB Correct: 7884 out of 500000 queries used.
9 Correct 2 ms 468 KB Correct: 9431 out of 500000 queries used.
10 Correct 2 ms 468 KB Correct: 9845 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Correct: 2968 out of 12000 queries used.
2 Correct 2 ms 596 KB Correct: 2974 out of 12000 queries used.
3 Correct 2 ms 596 KB Correct: 2995 out of 12000 queries used.
4 Correct 2 ms 596 KB Correct: 2974 out of 12000 queries used.
5 Correct 2 ms 596 KB Correct: 2968 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 596 KB Correct: 2968 out of 12000 queries used.
2 Correct 2 ms 596 KB Correct: 2974 out of 12000 queries used.
3 Correct 2 ms 596 KB Correct: 2995 out of 12000 queries used.
4 Correct 2 ms 596 KB Correct: 2974 out of 12000 queries used.
5 Correct 2 ms 596 KB Correct: 2968 out of 12000 queries used.
6 Correct 2 ms 468 KB Correct: 2989 out of 12000 queries used.
7 Correct 1 ms 596 KB Correct: 2983 out of 12000 queries used.
8 Correct 2 ms 596 KB Correct: 2995 out of 12000 queries used.
9 Correct 1 ms 596 KB Correct: 2986 out of 12000 queries used.
10 Correct 1 ms 596 KB Correct: 2977 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Correct: 2992 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 2995 out of 500000 queries used.
3 Correct 2 ms 468 KB Correct: 7790 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 8918 out of 500000 queries used.
5 Correct 3 ms 596 KB Correct: 16553 out of 500000 queries used.
6 Correct 2 ms 596 KB Correct: 2983 out of 500000 queries used.
7 Correct 3 ms 596 KB Correct: 29223 out of 500000 queries used.
8 Correct 2 ms 468 KB Correct: 7884 out of 500000 queries used.
9 Correct 2 ms 468 KB Correct: 9431 out of 500000 queries used.
10 Correct 2 ms 468 KB Correct: 9845 out of 500000 queries used.
11 Correct 1 ms 596 KB Correct: 2968 out of 12000 queries used.
12 Correct 2 ms 596 KB Correct: 2974 out of 12000 queries used.
13 Correct 2 ms 596 KB Correct: 2995 out of 12000 queries used.
14 Correct 2 ms 596 KB Correct: 2974 out of 12000 queries used.
15 Correct 2 ms 596 KB Correct: 2968 out of 12000 queries used.
16 Correct 2 ms 468 KB Correct: 2989 out of 12000 queries used.
17 Correct 1 ms 596 KB Correct: 2983 out of 12000 queries used.
18 Correct 2 ms 596 KB Correct: 2995 out of 12000 queries used.
19 Correct 1 ms 596 KB Correct: 2986 out of 12000 queries used.
20 Correct 1 ms 596 KB Correct: 2977 out of 12000 queries used.
21 Correct 2 ms 596 KB Correct: 2983 out of 25000 queries used.
22 Correct 2 ms 468 KB Correct: 7853 out of 25000 queries used.
23 Correct 1 ms 468 KB Correct: 3074 out of 25000 queries used.
24 Correct 2 ms 468 KB Correct: 5132 out of 25000 queries used.
25 Correct 2 ms 468 KB Correct: 7924 out of 25000 queries used.
26 Correct 3 ms 468 KB Correct: 7564 out of 25000 queries used.
27 Correct 2 ms 468 KB Correct: 7687 out of 25000 queries used.
28 Correct 2 ms 468 KB Correct: 8162 out of 25000 queries used.
29 Correct 3 ms 468 KB Correct: 8502 out of 25000 queries used.
30 Correct 2 ms 512 KB Correct: 8935 out of 25000 queries used.
31 Correct 2 ms 468 KB Correct: 8961 out of 25000 queries used.
32 Correct 2 ms 596 KB Correct: 2980 out of 25000 queries used.
33 Correct 2 ms 468 KB Correct: 8920 out of 25000 queries used.
34 Correct 3 ms 468 KB Correct: 8911 out of 25000 queries used.
35 Correct 2 ms 472 KB Correct: 8952 out of 25000 queries used.
36 Correct 2 ms 468 KB Correct: 9023 out of 25000 queries used.
37 Correct 2 ms 468 KB Correct: 8866 out of 25000 queries used.
38 Correct 2 ms 468 KB Correct: 9065 out of 25000 queries used.
39 Correct 2 ms 468 KB Correct: 8911 out of 25000 queries used.
40 Correct 2 ms 468 KB Correct: 8992 out of 25000 queries used.
41 Correct 2 ms 488 KB Correct: 8930 out of 25000 queries used.
42 Correct 2 ms 468 KB Correct: 8961 out of 25000 queries used.
43 Correct 1 ms 596 KB Correct: 2989 out of 25000 queries used.
44 Correct 2 ms 468 KB Correct: 8849 out of 25000 queries used.
45 Correct 2 ms 468 KB Correct: 8837 out of 25000 queries used.
46 Correct 2 ms 468 KB Correct: 8849 out of 25000 queries used.
47 Correct 2 ms 468 KB Correct: 8951 out of 25000 queries used.
48 Correct 2 ms 468 KB Correct: 9035 out of 25000 queries used.
49 Correct 2 ms 468 KB Correct: 8975 out of 25000 queries used.
50 Correct 2 ms 468 KB Correct: 8957 out of 25000 queries used.
51 Correct 2 ms 468 KB Correct: 8963 out of 25000 queries used.
52 Correct 2 ms 468 KB Correct: 8922 out of 25000 queries used.
53 Correct 2 ms 468 KB Correct: 9410 out of 25000 queries used.
54 Incorrect 3 ms 468 KB Too many calls to get_distance().
55 Halted 0 ms 0 KB -