Submission #399745

#TimeUsernameProblemLanguageResultExecution timeMemory
399745peuch도시들 (IOI15_towns)C++17
Compilation error
0 ms0 KiB
#include "towns.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "graderlib.c"


#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
 
const int MAXN = 310;
 
int dist[MAXN][MAXN];
int marc[MAXN][MAXN];

int getD(int i, int j){
	if(marc[i][j]) return dist[i][j];
	marc[i][j] = marc[j][i] = 1;
	if(i == j) return dist[i][j] = dist[j][i] = 0;
	return dist[i][j] = dist[j][i] = getDistance(i, j);
}
 
int hubDistance(int N, int sub) {
	int p1 = 0, p2 = 0;
	int maxi = 0;
	memset(dist, 0, sizeof(dist));
	memset(marc, 0, sizeof(marc));
	for(int i = 0; i < N; i++){
		int aux = getD(0, i);
		if(aux > maxi) p1 = i, maxi = aux;
	}
	maxi = 0;
	for(int i = 0; i < N; i++)
		if(getD(p1, i) > maxi) maxi = getD(p1, i), p2 = i;
	
	int diam = getD(p1, p2);
	int ans = 1e8;
	for(int i = 0; i < N; i++){
		int x = (diam + getD(p1, i) - getD(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 + getD(p1, i) - getD(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 = getD(p1, pilha.top());
				int x = (aux + getD(p1, lMid[i]) - getD(pilha.top(), lMid[i])) / 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 = getD(p1, k);
			int x = (aux + getD(p1, lMid[i]) - getD(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 = getD(p1, pilha.top());
				int x = (aux + getD(p1, rMid[i]) - getD(pilha.top(), rMid[i])) / 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 = getD(p1, k);
			int x = (aux + getD(p1, rMid[i]) - getD(k, rMid[i])) / 2;
			if(x > max(ans, diam - ans)) cnt++;
		}
		if(cnt > N / 2) return -ans;
		return ans;
	}
	return ans;
}



int main() {
    int ncase, R, N;
    int subtask;
    int ret;
    scanf("%d %d", &subtask, &ncase);
    for (int i = 0; i < ncase; i++) {
        scanf("%d", &N);
        _ini_query(N,subtask);
        R=hubDistance(N,subtask);
        printf("%d\n",R);
    }
    return 0;
}

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:56:52: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |   if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
      |                                        ~~~~~~~~~~~~^~~~~~~
towns.cpp:56:75: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   56 |   if(lSize > N / 2 || rSize > N / 2 || lMid.size() > N / 2 || rMid.size() > N / 2) return -ans;
      |                                                               ~~~~~~~~~~~~^~~~~~~
towns.cpp:61:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |  else if(lMid.size() > N / 2){
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |   for(int i = 0; i < lMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |   for(int i = 0; i < lMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:83:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   83 |  else if(rMid.size() > N / 2){
      |          ~~~~~~~~~~~~^~~~~~~
towns.cpp:85:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |   for(int i = 0; i < rMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp:97:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |   for(int i = 0; i < rMid.size(); i++){
      |                  ~~^~~~~~~~~~~~~
towns.cpp: In function 'int main()':
towns.cpp:113:9: warning: unused variable 'ret' [-Wunused-variable]
  113 |     int ret;
      |         ^~~
towns.cpp:114:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  114 |     scanf("%d %d", &subtask, &ncase);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
towns.cpp:116:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  116 |         scanf("%d", &N);
      |         ~~~~~^~~~~~~~~~
/tmp/ccjj8rpX.o: In function `_ini_query(int, int)':
grader.c:(.text+0x0): multiple definition of `_ini_query(int, int)'
/tmp/ccXMrMsk.o:towns.cpp:(.text+0x0): first defined here
/tmp/ccjj8rpX.o: In function `getDistance(int, int)':
grader.c:(.text+0x110): multiple definition of `getDistance(int, int)'
/tmp/ccXMrMsk.o:towns.cpp:(.text+0x110): first defined here
/tmp/ccjj8rpX.o: In function `main':
grader.c:(.text.startup+0x0): multiple definition of `main'
/tmp/ccXMrMsk.o:towns.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status