답안 #733966

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
733966 2023-05-01T12:27:51 Z vjudge1 City Mapping (NOI18_citymapping) C++17
57 / 100
120 ms 8880 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll inf = 1e15;
void find_roads(int N, int Q, int A[], int B[], int W[]) {
	if (Q == 500000) {
		vector<tuple<ll, int, int>> T;
		for (int i = 0; i < N; i++) {
			for (int j = i + 1; j < N; j++) {
				T.emplace_back(get_distance(i + 1, j + 1), i, j);
			}
		}
		sort(T.begin(), T.end());
		vector<int> par(N);
		iota(par.begin(), par.end(), 0);
		function<int(int)> find = [&](int x) {
			return x == par[x] ? x : par[x] = find(par[x]);
		};
		int p = 0;
		for (int i = 0; i < T.size(); i++) {
			auto [z, x, y] = T[i];
			if (find(x) != find(y)) {
				A[p] = x + 1;
				B[p] = y + 1;
				W[p] = z;
				p++;
				par[find(x)] = find(y);
			}
		}
		return;
	}
	if (Q == 12000) {
		int x = -1;
		ll mx = 0;
		for (int i = 1; i < N; i++) {
			ll s = get_distance(1, i + 1);
			if (s > mx) {
				mx = s;
				x = i;
			}
		}
		vector<pair<ll, int>> p(N);
		for (int i = 0; i < N; i++) {
			p[i] = {get_distance(x + 1, i + 1), i};
		}
		sort(p.begin(), p.end());
		for (int i = 0; i < N - 1; i++) {
			A[i] = p[i].second + 1;
			B[i] = p[i + 1].second + 1;
			W[i] = p[i + 1].first - p[i].first;
		}
		return;
	}
    int r = -1;
    ll mx = 0;
    for (int i = 1; i < N; i++) {
		ll s = get_distance(1, i + 1);
		if (s > mx) {
			mx = s;
			r = i;
		}
	}
	vector<ll> dis(N);
	for (int i = 0; i < N; i++) {
		dis[i] = i == r ? 0 : get_distance(r + 1, i + 1);
	}
	vector<int> p(N);
	iota(p.begin(), p.end(), 0);
	sort(p.begin(), p.end(), [&](int i, int j) {
		return dis[i] < dis[j];
	});
	vector<vector<int>> d(N);
	d[0].push_back(r);
	for (int i = 1; i < N; i++) {
		int v = p[i];
		vector<bool> f(N);
		int lo = 0, hi = N - 1;
		while (lo < hi) {
			int mi = (lo + hi + 1) / 2;
			bool ok = 0;
			for (int x : d[mi]) {
				if (dis[v] - dis[x] > 0 && dis[v] - dis[x] == get_distance(x + 1, v + 1)) {
					f[x] = 1;
					ok = 1;
					break;
				}
			}
			if (ok) {
				lo = mi;
			} else {
				hi = mi - 1;
			}
		}
		int u = -1;
		for (int x : d[lo]) {
			if (f[x]) {
				u = x;
			}
		}
		if (u == -1) {
			for (int x : d[lo]) {
				if (dis[v] - dis[x] > 0 && dis[v] - dis[x] == get_distance(x + 1, v + 1)) {
					u = x;
					break;
				}
			}
		}
		A[i - 1] = u + 1;
		B[i - 1] = v + 1;
		W[i - 1] = dis[v] - dis[u];
		d[lo + 1].push_back(v);
	}
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:21:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<long long int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for (int i = 0; i < T.size(); i++) {
      |                   ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 8812 KB Correct: 498501 out of 500000 queries used.
2 Correct 107 ms 8880 KB Correct: 499500 out of 500000 queries used.
3 Correct 101 ms 8740 KB Correct: 492528 out of 500000 queries used.
4 Correct 106 ms 8760 KB Correct: 494515 out of 500000 queries used.
5 Correct 114 ms 8668 KB Correct: 498501 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 8812 KB Correct: 498501 out of 500000 queries used.
2 Correct 107 ms 8880 KB Correct: 499500 out of 500000 queries used.
3 Correct 101 ms 8740 KB Correct: 492528 out of 500000 queries used.
4 Correct 106 ms 8760 KB Correct: 494515 out of 500000 queries used.
5 Correct 114 ms 8668 KB Correct: 498501 out of 500000 queries used.
6 Correct 87 ms 8760 KB Correct: 495510 out of 500000 queries used.
7 Correct 103 ms 8800 KB Correct: 497503 out of 500000 queries used.
8 Correct 88 ms 8772 KB Correct: 497503 out of 500000 queries used.
9 Correct 81 ms 8768 KB Correct: 495510 out of 500000 queries used.
10 Correct 95 ms 8736 KB Correct: 496506 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Correct: 1981 out of 12000 queries used.
2 Correct 1 ms 468 KB Correct: 1985 out of 12000 queries used.
3 Correct 1 ms 468 KB Correct: 1999 out of 12000 queries used.
4 Correct 1 ms 464 KB Correct: 1985 out of 12000 queries used.
5 Correct 1 ms 468 KB Correct: 1981 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 468 KB Correct: 1981 out of 12000 queries used.
2 Correct 1 ms 468 KB Correct: 1985 out of 12000 queries used.
3 Correct 1 ms 468 KB Correct: 1999 out of 12000 queries used.
4 Correct 1 ms 464 KB Correct: 1985 out of 12000 queries used.
5 Correct 1 ms 468 KB Correct: 1981 out of 12000 queries used.
6 Correct 2 ms 472 KB Correct: 1995 out of 12000 queries used.
7 Correct 1 ms 468 KB Correct: 1991 out of 12000 queries used.
8 Correct 1 ms 516 KB Correct: 1999 out of 12000 queries used.
9 Correct 1 ms 468 KB Correct: 1993 out of 12000 queries used.
10 Correct 1 ms 464 KB Correct: 1987 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 120 ms 8812 KB Correct: 498501 out of 500000 queries used.
2 Correct 107 ms 8880 KB Correct: 499500 out of 500000 queries used.
3 Correct 101 ms 8740 KB Correct: 492528 out of 500000 queries used.
4 Correct 106 ms 8760 KB Correct: 494515 out of 500000 queries used.
5 Correct 114 ms 8668 KB Correct: 498501 out of 500000 queries used.
6 Correct 87 ms 8760 KB Correct: 495510 out of 500000 queries used.
7 Correct 103 ms 8800 KB Correct: 497503 out of 500000 queries used.
8 Correct 88 ms 8772 KB Correct: 497503 out of 500000 queries used.
9 Correct 81 ms 8768 KB Correct: 495510 out of 500000 queries used.
10 Correct 95 ms 8736 KB Correct: 496506 out of 500000 queries used.
11 Correct 2 ms 468 KB Correct: 1981 out of 12000 queries used.
12 Correct 1 ms 468 KB Correct: 1985 out of 12000 queries used.
13 Correct 1 ms 468 KB Correct: 1999 out of 12000 queries used.
14 Correct 1 ms 464 KB Correct: 1985 out of 12000 queries used.
15 Correct 1 ms 468 KB Correct: 1981 out of 12000 queries used.
16 Correct 2 ms 472 KB Correct: 1995 out of 12000 queries used.
17 Correct 1 ms 468 KB Correct: 1991 out of 12000 queries used.
18 Correct 1 ms 516 KB Correct: 1999 out of 12000 queries used.
19 Correct 1 ms 468 KB Correct: 1993 out of 12000 queries used.
20 Correct 1 ms 464 KB Correct: 1987 out of 12000 queries used.
21 Correct 2 ms 468 KB Correct: 7009 out of 25000 queries used.
22 Correct 2 ms 468 KB Correct: 9729 out of 25000 queries used.
23 Correct 2 ms 468 KB Correct: 9309 out of 25000 queries used.
24 Correct 2 ms 468 KB Correct: 9807 out of 25000 queries used.
25 Incorrect 3 ms 496 KB Too many calls to get_distance().
26 Halted 0 ms 0 KB -