답안 #964765

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
964765 2024-04-17T13:54:33 Z guechotjrhh City Mapping (NOI18_citymapping) C++14
32 / 100
2 ms 856 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();
	
	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 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);

	//for (int i = 0; i < N - 1; i++) cout << a[i] << ' ' << b[i] << ' ' << w[i] << endl;

	return;
}
/*
5 500000 1
1 4 8
4 2 1
4 3 7
3 5 3
*/

Compilation message

citymapping.cpp: In function 'void func(std::vector<std::pair<long long int, long long int> >&)':
citymapping.cpp:92:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |    for (int j = 0; j < nv[i].size(); j++) nv[i][j].y -= o;
      |                    ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2993 out of 500000 queries used.
2 Correct 2 ms 684 KB Correct: 3255 out of 500000 queries used.
3 Incorrect 2 ms 604 KB Reported list of edges differ from actual.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2993 out of 500000 queries used.
2 Correct 2 ms 684 KB Correct: 3255 out of 500000 queries used.
3 Incorrect 2 ms 604 KB Reported list of edges differ from actual.
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2969 out of 12000 queries used.
2 Correct 2 ms 604 KB Correct: 2975 out of 12000 queries used.
3 Correct 2 ms 604 KB Correct: 2996 out of 12000 queries used.
4 Correct 2 ms 604 KB Correct: 2975 out of 12000 queries used.
5 Correct 1 ms 600 KB Correct: 2969 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2969 out of 12000 queries used.
2 Correct 2 ms 604 KB Correct: 2975 out of 12000 queries used.
3 Correct 2 ms 604 KB Correct: 2996 out of 12000 queries used.
4 Correct 2 ms 604 KB Correct: 2975 out of 12000 queries used.
5 Correct 1 ms 600 KB Correct: 2969 out of 12000 queries used.
6 Correct 1 ms 604 KB Correct: 2990 out of 12000 queries used.
7 Correct 2 ms 540 KB Correct: 2984 out of 12000 queries used.
8 Correct 1 ms 604 KB Correct: 2996 out of 12000 queries used.
9 Correct 2 ms 604 KB Correct: 2987 out of 12000 queries used.
10 Correct 1 ms 856 KB Correct: 2978 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Correct: 2993 out of 500000 queries used.
2 Correct 2 ms 684 KB Correct: 3255 out of 500000 queries used.
3 Incorrect 2 ms 604 KB Reported list of edges differ from actual.
4 Halted 0 ms 0 KB -