Submission #119455

# Submission time Handle Problem Language Result Execution time Memory
119455 2019-06-21T09:28:40 Z PeppaPig Towns (IOI15_towns) C++14
13 / 100
19 ms 676 KB
#include "towns.h"
#include <bits/stdc++.h>

using namespace std;

const int N = 205;

struct UnionFind {
	int par[N], sz[N];
	void init() {
		iota(par, par+N, 0);
		fill_n(sz, N, 1);
	}
	int find(int x) {
		return x == par[x] ? x : find(par[x]);
	}
	void unite(int a, int b) {
		a = find(a), b = find(b);
		if(a == b) return;
		if(sz[a] > sz[b]) swap(a, b);
		par[a] = b, sz[b] += sz[a];
	}
	int size(int a) {
		return sz[find(a)];
	}
} dsu;

int hubDistance(int n, int sub) {
	vector<vector<int> > d(N, vector<int>(N, 0));
	auto get_dist = [&](int a, int b) {
		if(a == b) return 0;
		else if(d[a][b]) return d[a][b];
		else return d[a][b] = d[b][a] = getDistance(a, b);
	};	

	int a, b;
	for(int i = 0, mx = -1; i < n; i++) if(get_dist(0, i) > mx) a = i, mx = get_dist(0, i);
	for(int i = 0, mx = -1; i < n; i++) if(get_dist(a, i) > mx) b = i, mx = get_dist(a, i);

	int lim = (get_dist(a, b) + get_dist(a, 0) - get_dist(b, 0)) / 2;
	vector<int> hub;
	int root1 = -1, root2 = -1, ans = INT_MAX;
	for(int i = 0; i < n; i++) {
		int pos = (get_dist(a, i) + get_dist(a, 0) - get_dist(i, 0)) / 2;
		hub.emplace_back(pos);
		ans = min(ans, max(pos, get_dist(a, b) - pos));
		if(get_dist(a, i) == get_dist(a, b)) {
			if(root1 == -1) root1 = pos;
			else if(pos != root1) root2 = pos;
		}
	}
	sort(hub.begin(), hub.end());
	hub.resize(unique(hub.begin(), hub.end()) - hub.begin());	

	auto chk = [&](int root) {
		int l = 0, r = 0;
		for(int i = 0; i < n; i++) {
			int pos = (get_dist(a, i) + get_dist(a, 0) - get_dist(i, 0)) / 2;
			if(pos < root) ++l;
			if(pos > root) ++r;
		}
		return (l <= n / 2 && r <= n / 2);
	};
	//if(!chk(root1) && (root2 == -1 || !chk(root2))) return -ans;

	auto same = [&](int root, int x, int y) {
		int px = (get_dist(a, x) + get_dist(0, x) - get_dist(a, 0)) / 2;
		int py = (get_dist(a, y) + get_dist(0, y) - get_dist(a, 0)) / 2;
		return get_dist(x, y) != px + py;
	};

	auto chk2 = [&](int root) {
		dsu.init();
		vector<int> v;
		for(int i = 0; i < n; i++) {
			int pos = (get_dist(a, i) + get_dist(a, 0) - get_dist(i, 0)) / 2;
			if(pos == root) v.emplace_back(i);
		} 
		for(int i = 0; i < v.size(); i++) for(int j = i + 1; j < v.size(); j++) {
			if(same(root, v[i], v[j])) dsu.unite(v[i], v[j]);
		}
		int mx = -1;
		for(int i = 0; i < v.size(); i++) mx = max(mx, dsu.size(i));
		return mx <= n / 2;
	};	

	if(!chk2(root1) && (root2 == -1 || !chk2(root2))) return -ans;

	return ans;

	auto majority_vote = [&](int root) {

	};
}

Compilation message

towns.cpp: In lambda function:
towns.cpp:66:22: warning: unused parameter 'root' [-Wunused-parameter]
  auto same = [&](int root, int x, int y) {
                      ^~~~
towns.cpp: In lambda function:
towns.cpp:79:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); i++) for(int j = i + 1; j < v.size(); j++) {
                  ~~^~~~~~~~~~
towns.cpp:79:58: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); i++) for(int j = i + 1; j < v.size(); j++) {
                                                        ~~^~~~~~~~~~
towns.cpp:83:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < v.size(); i++) mx = max(mx, dsu.size(i));
                  ~~^~~~~~~~~~
towns.cpp: In lambda function:
towns.cpp:91:31: warning: unused parameter 'root' [-Wunused-parameter]
  auto majority_vote = [&](int root) {
                               ^~~~
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:40:6: warning: unused variable 'lim' [-Wunused-variable]
  int lim = (get_dist(a, b) + get_dist(a, 0) - get_dist(b, 0)) / 2;
      ^~~
towns.cpp:55:7: warning: variable 'chk' set but not used [-Wunused-but-set-variable]
  auto chk = [&](int root) {
       ^~~
towns.cpp:91:7: warning: variable 'majority_vote' set but not used [-Wunused-but-set-variable]
  auto majority_vote = [&](int root) {
       ^~~~~~~~~~~~~
towns.cpp:28:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int n, int sub) {
                            ^~~
towns.cpp:31:3: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(a == b) return 0;
   ^~
towns.cpp:31:3: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if(a == b) return 0;
   ^~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 668 KB Output is correct
2 Correct 16 ms 672 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 18 ms 660 KB Output is correct
5 Correct 19 ms 676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 15 ms 668 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 552 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 552 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 552 KB Output isn't correct
2 Halted 0 ms 0 KB -