답안 #400248

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400248 2021-05-07T18:05:25 Z peuch 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include "towns.h"
#include<bits/stdc++.h>
using namespace std;
 
const int MAXN = 310;
 
int dist[MAXN][MAXN];
int marc[MAXN][MAXN];
int p1, p2, n;
int cnt; 
 
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;
	cnt++;
	return dist[i][j] = dist[j][i] = getDistance(i, j);
}
 
int getSize(vector<int> values, int goal){
	vector<multiset<int> > alive, dead;
	for(int i = 0; i < values.size(); i++){
		multiset<int> aux;
		aux.insert(values[i]);
		alive.push_back(aux);
	}
	while(alive.size() > 1){
		if(alive.size() % 2 == 1) {
			dead.push_back(alive.back());
			alive.pop_back();
		}
		vector<multiset<int> > aux;
		for(int i = 0; i < alive.size(); i += 2){
			multiset<int> g1, g2;
			g1 = alive[i];
			g2 = alive[i + 1];
			int v1 = *g1.begin(), v2 = *g2.begin();
			int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2;
			if(x != goal){
				while(!g2.empty()){
					g1.insert(*g2.begin());
					g2.erase(g2.begin());
				}
				aux.push_back(g1);
			}
			else{
				dead.push_back(g1);
				dead.push_back(g2);
			}
		}
		alive = aux;
	}
	if(alive.empty()) return 1;
	for(int i = 0; i < dead.size(); i++){
		multiset<int> g1, g2;
		g1 = alive[0];
		g2 = dead[i];
		int v1 = *g1.begin(), v2 = *g2.begin();
		int x = (getD(p1, v1) + getD(p1, v2) - getD(v1, v2)) / 2;
		if(x != goal){
			while(!g2.empty()){
				g1.insert(*g2.begin());
				g2.erase(g2.begin());
			}
			alive[0] = g1;
		}
	}
	return (alive[0].size() > n / 2) ? -1 : 1;
}
 
int hubDistance(int N, int sub) {
	srand(time(0));
	n = N;
	p1 = 0, p2 = 0;
	int maxi = 0;
	cnt = 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 cruz0 = (diam + getD(p1, 0) - getD(p2, 0)) / 2;
	int ans = max(cruz0, diam - cruz0);
	for(int i = 0; i < N; i++){
		int x = (getD(p1, 0) + getD(p1, i) - getD(0, 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 = (getD(p1, 0) + getD(p1, i) - getD(0, 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(lSize > N / 2 || rSize > N / 2) return -ans;
	else if(lMid.size() > N / 2)
		return getSize(lMid, min(ans, diam - ans)) * ans;
	else if(rMid.size() > N / 2)
		return getSize(rMid, max(ans, diam - ans)) * ans;
	return ans;
}

Compilation message

dreaming.cpp:1:10: fatal error: towns.h: No such file or directory
    1 | #include "towns.h"
      |          ^~~~~~~~~
compilation terminated.