답안 #963471

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963471 2024-04-15T06:14:02 Z Issa City Mapping (NOI18_citymapping) C++17
32 / 100
50 ms 860 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 1e3 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 30;
const int P = 31;

long long get_distance(int X, int Y);

int n;
vector<int> g[maxn];
ll d[maxn][maxn];
vector<pii> ans;
int sz[maxn];
int mx[maxn];

void get(int v, int del){
	sz[v] = 1; mx[v] = 0;
	for(int to: g[v]){
		if(to == del) continue;
		get(to, del);
		sz[v] += sz[to];
		if(sz[to] > sz[mx[v]]) mx[v] = to;
	}
}

void find_roads(int N, int Q, int A[], int B[], int W[]){
	n = N;
	vector<int> v;
	for(int i = 2; i <= n; i++){
		v.push_back(i);
		d[1][i] = get_distance(1, i);
	}
	sort(v.begin(), v.end(), [](int i, int j){
		return d[1][i] < d[1][j];
	});
	int edg = 0;
	for(int i: v){
		int r = 1, del = 0;
		while(true){
			get(r, del);
			vector<int> s;
			s.push_back(r);
			while(mx[s.back()]){
				s.push_back(mx[s.back()]);
			}
			if(s.size() == 1) break;
			ll x = d[1][s.back()] + d[1][i] - get_distance(s.back(), i);
			x /= 2; int j = 0;
			while(d[1][s[j]] != x) j++;
			r = s[j]; 
			if(j + 1 < s.size()) del = s[j+1];
			else del = 0;
		}
		A[edg] = r; B[edg] = i;
		W[edg] = d[1][i] - d[1][r];
		edg++; g[r].push_back(i);
	}
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:59:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    if(j + 1 < s.size()) del = s[j+1];
      |       ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 600 KB Correct: 2695 out of 500000 queries used.
2 Correct 5 ms 756 KB Correct: 2428 out of 500000 queries used.
3 Correct 5 ms 604 KB Correct: 4527 out of 500000 queries used.
4 Incorrect 50 ms 632 KB Too many calls to get_distance().
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 600 KB Correct: 2695 out of 500000 queries used.
2 Correct 5 ms 756 KB Correct: 2428 out of 500000 queries used.
3 Correct 5 ms 604 KB Correct: 4527 out of 500000 queries used.
4 Incorrect 50 ms 632 KB Too many calls to get_distance().
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Correct: 2082 out of 12000 queries used.
2 Correct 8 ms 696 KB Correct: 2321 out of 12000 queries used.
3 Correct 7 ms 600 KB Correct: 2459 out of 12000 queries used.
4 Correct 7 ms 604 KB Correct: 2466 out of 12000 queries used.
5 Correct 9 ms 860 KB Correct: 2232 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 716 KB Correct: 2082 out of 12000 queries used.
2 Correct 8 ms 696 KB Correct: 2321 out of 12000 queries used.
3 Correct 7 ms 600 KB Correct: 2459 out of 12000 queries used.
4 Correct 7 ms 604 KB Correct: 2466 out of 12000 queries used.
5 Correct 9 ms 860 KB Correct: 2232 out of 12000 queries used.
6 Correct 8 ms 600 KB Correct: 2473 out of 12000 queries used.
7 Correct 7 ms 604 KB Correct: 2382 out of 12000 queries used.
8 Correct 7 ms 604 KB Correct: 2207 out of 12000 queries used.
9 Correct 8 ms 712 KB Correct: 2235 out of 12000 queries used.
10 Correct 7 ms 604 KB Correct: 2302 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 600 KB Correct: 2695 out of 500000 queries used.
2 Correct 5 ms 756 KB Correct: 2428 out of 500000 queries used.
3 Correct 5 ms 604 KB Correct: 4527 out of 500000 queries used.
4 Incorrect 50 ms 632 KB Too many calls to get_distance().
5 Halted 0 ms 0 KB -