답안 #702430

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
702430 2023-02-24T05:05:22 Z GusterGoose27 City Mapping (NOI18_citymapping) C++11
88.27 / 100
3 ms 612 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(0);
ll dist[2][MAXN];

void make_ans(vector<int> &vals, int a[], int b[], int w[]) {
	if (vals.size() == 1) 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, vector<int>> 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));
		}
	}
	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++) {
		buckets[dist[1][i]-dist[0][i]].push_back(vals[i]);
	}
	for (auto it: buckets) {
		make_ans(it.second, 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);
	return;
}

Compilation message

citymapping.cpp: In function 'void make_ans(std::vector<int>&, int*, int*, int*)':
citymapping.cpp:48: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]
   48 |  for (int i = 0; i < path.size()-1; i++) {
      |                  ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Correct: 2728 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 3265 out of 500000 queries used.
3 Correct 2 ms 476 KB Correct: 6494 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 6965 out of 500000 queries used.
5 Correct 2 ms 468 KB Correct: 4411 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Correct: 2728 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 3265 out of 500000 queries used.
3 Correct 2 ms 476 KB Correct: 6494 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 6965 out of 500000 queries used.
5 Correct 2 ms 468 KB Correct: 4411 out of 500000 queries used.
6 Correct 2 ms 596 KB Correct: 3067 out of 500000 queries used.
7 Correct 1 ms 468 KB Correct: 2897 out of 500000 queries used.
8 Correct 2 ms 468 KB Correct: 6662 out of 500000 queries used.
9 Correct 2 ms 468 KB Correct: 7384 out of 500000 queries used.
10 Correct 2 ms 468 KB Correct: 5068 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Correct: 2049 out of 12000 queries used.
2 Correct 2 ms 596 KB Correct: 3062 out of 12000 queries used.
3 Correct 2 ms 596 KB Correct: 3170 out of 12000 queries used.
4 Correct 1 ms 596 KB Correct: 2112 out of 12000 queries used.
5 Correct 2 ms 596 KB Correct: 2030 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Correct: 2049 out of 12000 queries used.
2 Correct 2 ms 596 KB Correct: 3062 out of 12000 queries used.
3 Correct 2 ms 596 KB Correct: 3170 out of 12000 queries used.
4 Correct 1 ms 596 KB Correct: 2112 out of 12000 queries used.
5 Correct 2 ms 596 KB Correct: 2030 out of 12000 queries used.
6 Correct 2 ms 528 KB Correct: 3161 out of 12000 queries used.
7 Correct 2 ms 604 KB Correct: 2791 out of 12000 queries used.
8 Correct 2 ms 608 KB Correct: 3116 out of 12000 queries used.
9 Correct 2 ms 596 KB Correct: 3314 out of 12000 queries used.
10 Correct 2 ms 608 KB Correct: 2447 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Correct: 2728 out of 500000 queries used.
2 Correct 2 ms 468 KB Correct: 3265 out of 500000 queries used.
3 Correct 2 ms 476 KB Correct: 6494 out of 500000 queries used.
4 Correct 2 ms 468 KB Correct: 6965 out of 500000 queries used.
5 Correct 2 ms 468 KB Correct: 4411 out of 500000 queries used.
6 Correct 2 ms 596 KB Correct: 3067 out of 500000 queries used.
7 Correct 1 ms 468 KB Correct: 2897 out of 500000 queries used.
8 Correct 2 ms 468 KB Correct: 6662 out of 500000 queries used.
9 Correct 2 ms 468 KB Correct: 7384 out of 500000 queries used.
10 Correct 2 ms 468 KB Correct: 5068 out of 500000 queries used.
11 Correct 3 ms 596 KB Correct: 2049 out of 12000 queries used.
12 Correct 2 ms 596 KB Correct: 3062 out of 12000 queries used.
13 Correct 2 ms 596 KB Correct: 3170 out of 12000 queries used.
14 Correct 1 ms 596 KB Correct: 2112 out of 12000 queries used.
15 Correct 2 ms 596 KB Correct: 2030 out of 12000 queries used.
16 Correct 2 ms 528 KB Correct: 3161 out of 12000 queries used.
17 Correct 2 ms 604 KB Correct: 2791 out of 12000 queries used.
18 Correct 2 ms 608 KB Correct: 3116 out of 12000 queries used.
19 Correct 2 ms 596 KB Correct: 3314 out of 12000 queries used.
20 Correct 2 ms 608 KB Correct: 2447 out of 12000 queries used.
21 Correct 2 ms 612 KB Correct: 2896 out of 25000 queries used.
22 Correct 2 ms 468 KB Correct: 3956 out of 25000 queries used.
23 Correct 1 ms 468 KB Correct: 4149 out of 25000 queries used.
24 Correct 2 ms 480 KB Correct: 3566 out of 25000 queries used.
25 Correct 2 ms 468 KB Correct: 6629 out of 25000 queries used.
26 Correct 2 ms 604 KB Correct: 6606 out of 25000 queries used.
27 Correct 2 ms 468 KB Correct: 6423 out of 25000 queries used.
28 Correct 2 ms 468 KB Correct: 6493 out of 25000 queries used.
29 Correct 2 ms 400 KB Correct: 6792 out of 25000 queries used.
30 Correct 2 ms 468 KB Correct: 7046 out of 25000 queries used.
31 Correct 2 ms 468 KB Correct: 7063 out of 25000 queries used.
32 Correct 2 ms 596 KB Correct: 2509 out of 25000 queries used.
33 Correct 3 ms 468 KB Correct: 6945 out of 25000 queries used.
34 Correct 3 ms 476 KB Correct: 7003 out of 25000 queries used.
35 Correct 2 ms 468 KB Correct: 6991 out of 25000 queries used.
36 Correct 2 ms 468 KB Correct: 6966 out of 25000 queries used.
37 Correct 2 ms 468 KB Correct: 6977 out of 25000 queries used.
38 Correct 2 ms 468 KB Correct: 7017 out of 25000 queries used.
39 Correct 2 ms 468 KB Correct: 6931 out of 25000 queries used.
40 Correct 2 ms 476 KB Correct: 7053 out of 25000 queries used.
41 Correct 2 ms 468 KB Correct: 7173 out of 25000 queries used.
42 Correct 2 ms 468 KB Correct: 6927 out of 25000 queries used.
43 Correct 1 ms 596 KB Correct: 2262 out of 25000 queries used.
44 Correct 2 ms 476 KB Correct: 7010 out of 25000 queries used.
45 Correct 2 ms 468 KB Correct: 6965 out of 25000 queries used.
46 Correct 2 ms 468 KB Correct: 7003 out of 25000 queries used.
47 Correct 2 ms 468 KB Correct: 7185 out of 25000 queries used.
48 Correct 2 ms 468 KB Correct: 7004 out of 25000 queries used.
49 Correct 2 ms 468 KB Correct: 6958 out of 25000 queries used.
50 Correct 2 ms 480 KB Correct: 6926 out of 25000 queries used.
51 Correct 2 ms 468 KB Correct: 7102 out of 25000 queries used.
52 Correct 2 ms 468 KB Correct: 7114 out of 25000 queries used.
53 Correct 2 ms 468 KB Correct: 8101 out of 25000 queries used.
54 Correct 1 ms 484 KB Correct: 3580 out of 25000 queries used.
55 Correct 2 ms 468 KB Correct: 7102 out of 25000 queries used.
56 Correct 2 ms 468 KB Correct: 7004 out of 25000 queries used.
57 Correct 2 ms 468 KB Correct: 6947 out of 25000 queries used.
58 Correct 2 ms 480 KB Correct: 6893 out of 25000 queries used.
59 Correct 2 ms 480 KB Correct: 7095 out of 25000 queries used.
60 Correct 2 ms 468 KB Correct: 6636 out of 25000 queries used.
61 Correct 2 ms 476 KB Correct: 6538 out of 25000 queries used.
62 Correct 2 ms 528 KB Correct: 4757 out of 25000 queries used.
63 Correct 2 ms 468 KB Correct: 5603 out of 25000 queries used.
64 Correct 2 ms 468 KB Correct: 5100 out of 25000 queries used.
65 Correct 2 ms 468 KB Correct: 2571 out of 25000 queries used.
66 Correct 2 ms 484 KB Correct: 6725 out of 25000 queries used.
67 Correct 2 ms 468 KB Correct: 3990 out of 25000 queries used.
68 Correct 1 ms 480 KB Correct: 2682 out of 25000 queries used.
69 Correct 1 ms 468 KB Correct: 4057 out of 25000 queries used.
70 Correct 2 ms 468 KB Correct: 4992 out of 25000 queries used.