제출 #399735

#제출 시각아이디문제언어결과실행 시간메모리
399735peuch도시들 (IOI15_towns)C++17
0 / 100
22 ms424 KiB
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;

const int MAXN = 110;

int dist[MAXN][MAXN];

int hubDistance(int N, int sub) {
	int p1 = 0, p2 = 0;
	int maxi = 0;
	map<pair<int, int>, int> marc;
	for(int i = 0; i < N; i++){
		if(marc[make_pair(0, i)] == 0){
			marc[make_pair(0, i)] = 1;
			marc[make_pair(i, 0)] = 1;
			dist[i][0] = dist[0][i] = getDistance(0, i);
		}
		if(dist[i][0] > maxi) p1 = i, maxi = dist[i][0];
	}
	maxi = 0;
	for(int i = 0; i < N; i++){
		if(marc[make_pair(p1, i)] == 0){
			marc[make_pair(p1, i)] = 1;
			marc[make_pair(i, p1)] = 1;
			dist[i][p1] = dist[p1][i] = getDistance(p1, i);
		}
		if(dist[p1][i] > maxi) maxi = dist[p1][i], p2 = i;
	}
	for(int i = 0; i < N; i++){
		if(marc[make_pair(p2, i)] == 0){
			marc[make_pair(p2, i)] = 1;
			marc[make_pair(i, p2)] = 1;
			dist[i][p2] = dist[p2][i] = getDistance(p2, i);
		}
	}
	
	int diam = dist[p1][p2];
	int ans = MAXN;
	for(int i = 0; i < N; i++){
		int x = (diam + dist[p1][i] - dist[p2][i]) / 2;
		ans = min(ans, max(x, diam - x));
	}
	
	if(sub <= 2) return ans;
	
	int lSize = 0, rSize = 0;
	vector<int> lMid, rMid;
	for(int i = 0; i < N; i++){
		int x = (diam + dist[p1][i] - dist[p2][i]) / 2;
		if(x < min(ans, diam - ans)) lSize++;
		else if(x == min(ans, diam - ans)) lMid.push_back(i); 
		else if(x == max(ans, diam - ans)) rMid.push_back(i);
		else rSize++;
	}
	if(sub <= 4){
		if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
		return ans;
	}
	
	if(lSize > N / 2 || rSize > N / 2) return -ans;
	else if(lMid.size() > N / 2){
		stack<int> pilha;
		for(int i = 0; i < lMid.size(); i++){
			if(pilha.empty()) pilha.push(lMid[i]);
			else{
				int aux = dist[p1][pilha.top()];
				if(marc[make_pair(pilha.top(), lMid[i])] == 0){
					marc[make_pair(pilha.top(), lMid[i])] = 1;
					marc[make_pair(lMid[i], pilha.top())] = 1;
					dist[lMid[i]][pilha.top()] = dist[pilha.top()][lMid[i]] = getDistance(pilha.top(), lMid[i]);
				}
				int x = (aux + dist[p1][lMid[i]] - dist[lMid[i]][pilha.top()]) / 2;
				if(x == min(ans, diam - ans)) pilha.pop();
				else pilha.push(lMid[i]);
			}
		}
		if(pilha.empty()) return ans;
		int k = pilha.top();
		int cnt = 0;
		for(int i = 0; i < lMid.size(); i++){
			int aux = dist[p1][k];
			if(marc[make_pair(k, lMid[i])] == 0){
				marc[make_pair(k, lMid[i])] = 1;
				marc[make_pair(lMid[i], k)] = 1;
				dist[lMid[i]][k] = dist[k][lMid[i]] = getDistance(k, lMid[i]);
			}
			int x = (aux + dist[p1][lMid[i]] - dist[k][lMid[i]]) / 2;
			if(x > min(ans, diam - ans)) cnt++;
		}
		if(cnt > N / 2) return -ans;
		return ans;
	}
	else if(rMid.size() > N / 2){
		stack<int> pilha;
		for(int i = 0; i < rMid.size(); i++){
			if(pilha.empty()) pilha.push(rMid[i]);
			else{
				int aux = dist[p1][pilha.top()];
				if(marc[make_pair(pilha.top(), rMid[i])] == 0){
					marc[make_pair(pilha.top(), rMid[i])] = 1;
					marc[make_pair(rMid[i], pilha.top())] = 1;
					dist[lMid[i]][pilha.top()] = dist[pilha.top()][rMid[i]] = getDistance(pilha.top(), rMid[i]);
				}
				int x = (aux + dist[p1][rMid[i]] - dist[rMid[i]][pilha.top()]) / 2;
				if(x == max(ans, diam - ans)) pilha.pop();
				else pilha.push(rMid[i]);
			}
		}
		if(pilha.empty()) return ans;
		int k = pilha.top();
		int cnt = 0;
		for(int i = 0; i < rMid.size(); i++){
			int aux = dist[p1][k];
			if(marc[make_pair(k, rMid[i])] == 0){
				marc[make_pair(k, rMid[i])] = 1;
				marc[make_pair(rMid[i], k)] = 1;
				dist[rMid[i]][k] = dist[k][rMid[i]] = getDistance(k, rMid[i]);
			}
			int x = (aux + dist[p1][rMid[i]] - dist[k][rMid[i]]) / 2;
			if(x > max(ans, diam - ans)) cnt++;
		}
		if(cnt > N / 2) return -ans;
		return ans;
	}
	return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:57:52: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |   if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
      |                                        ~~~~~~~~~~~~^~~~~~~
towns.cpp:57:75: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   57 |   if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
      |                                                               ~~~~~~~~~~~~^~~~~~~
towns.cpp:62:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   62 |  else if(lMid.size() > N / 2){
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:64:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   64 |   for(int i = 0; i < lMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:81:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |   for(int i = 0; i < lMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:94:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   94 |  else if(rMid.size() > N / 2){
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:96:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |   for(int i = 0; i < rMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:113:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  113 |   for(int i = 0; i < rMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...