답안 #868054

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
868054 2023-10-30T10:25:25 Z waldi 도시들 (IOI15_towns) C++17
0 / 100
10 ms 468 KB
#include "towns.h"
#include <bits/stdc++.h>
#define FOR(i,p,k) for(int i=(p);i<=(k);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define fi first
#define se second
#define debug(a) cerr << #a << ": " << a << "\n";
using namespace std;
typedef pair<int, int> pii;

int hubDistance(int n, int sub){
	int a = 0;
	vector<int> od0(n, 0);
	FOR(i, 1, n-1){
		od0[i] = getDistance(0, i);
		if(od0[i] > od0[a]) a = i;
	}
	
	int b = 0;
	vector<int> oda(n, 0);
	REP(i, n) if(i != a){
		oda[i] = getDistance(a, i);
		if(oda[i] > oda[b]) b = i;
	}
	int sred = oda[b];
	
	vector<int> odb(n, 0);
	REP(i, n) if(i != b) odb[i] = getDistance(b, i);
	
	auto odsred = [&](int i){
		return (oda[i]+odb[i]-sred)>>1;
	};
	auto gdzie = [&](int i){
		return oda[i]-odsred(i);
	};
	auto odleglosc = [&](int i, int poz){
		return odsred(i) + abs(poz-gdzie(i));
	};
	
	set<int> secik;
	REP(i, n) secik.emplace(odsred(i));
	
	int wyn = sred+1, poz = -1;
	for(int off : secik){
		int maks = 0;
		REP(i, n) maks = max(maks, odleglosc(i, off));
		if(maks < wyn) wyn = maks, poz = off;
	}
	
	if(sub <= 2) return wyn;
	
	if(sub == 4){
		int lewo = 0, prawo = 0, ja = 0;
		REP(i, n){
			int odla = gdzie(i);
			if(odla < poz) ++lewo;
			if(odla == poz) ++ja;
			if(odla > poz) ++prawo;
		}
		bool zle = 0;
		zle |= lewo > n/2;
		zle |= prawo > n/2;
		zle |= ja > n/2;// wiem to jest jedno poddrzewo
		if(zle) wyn = -wyn;
		return wyn;
	}
	
	auto rowne = [&](int x, int y){
		return getDistance(x, y) < odleglosc(x, poz)+odleglosc(y, poz);
	};
	int lider = 0, licznik = 1;
	FOR(i, 1, n-1){
		if(rowne(lider, i)) ++licznik;
		else --licznik;
		if(!licznik) lider = i, licznik = 1;
	}
	int ile = 0;
	REP(i, n) if(rowne(i, lider)) ++ile;
	if(ile > n/2) wyn = -wyn;
	
	return wyn;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -