Submission #60642

# Submission time Handle Problem Language Result Execution time Memory
60642 2018-07-24T12:59:10 Z reality Towns (IOI15_towns) C++17
25 / 100
46 ms 912 KB
#include "towns.h"
#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
 
const int N = 256;
 
int D[N][N];
 
int get(int x,int y) {
	if (D[x][y] != -1)
		return D[x][y];
	return D[x][y] = D[y][x] = getDistance(x,y);
}
 
int hubDistance(int n, int sub) {
	srand(time(0));
	const int root = 0;//rand() % n;
	memset(D,-1,sizeof(D));
	int x = 0;
	for (int i = 0;i < n;++i)
		D[i][i] = 0;
	for (int i = 0;i < n;++i)
		if (get(root,i) > get(root,x))
			x = i;
	int y = x;
	for (int i = 0;i < n;++i)
		if (get(x,i) > get(x,y))
			y = i;
	vi s;
	for (int k = 0;k < n;++k)
		s.pb((get(root,x) - get(root,k) + get(x,k)) / 2);
	sort(all(s));
	int dist = -1;
	int ans = 2e9;
	for (auto it : s)
		smin(ans,max(it,get(x,y) - it));
	return ans;
	for (auto it : s)
		if (max(it,get(x,y) - it) == ans)
			dist = it;
	int a = 0,b = 0;
	vi was(n,0);
	for (int k = 0;k < n;++k) {
		int df = get(x,k) - get(root,k);
		int sm = get(root,x);
		if (df + sm < 2 * dist)
			was[k] = 1,++a;
		else
		if (df + sm > 2 * dist)
			was[k] = 1,++b;
	}
	if (max(a,b) > (n / 2))
		return -ans;
	vi v;
	for (int k = 0;k < n;++k)
		if (!was[k])
			v.pb(k);
	auto ok = [&](int A,int B) {
		return get(A,B) == get(A,x) + get(B,x) - 2 * dist;
	};
	int cnt = 0,cur = -1;
	int sz = v.size();
	for (int i = 0;cnt <= (n / 2) && i < sz;++i) {
		if (!cnt) {
			cnt = 1;
			cur = v[i];
		} else 
		if (ok(v[i],cur))
			++cnt;
		else
			--cnt;
	}
	if (cnt > (n / 2))
		return -ans;
	int nr = 0;
	for (int i = 0;i < sz;++i)
		if (ok(cur,v[i]))
			++nr;
	if (nr <= (n / 2))
		return ans;
	else
		return -ans;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:29:12: warning: conversion to 'unsigned int' from 'time_t {aka long int}' may alter its value [-Wconversion]
  srand(time(0));
        ~~~~^~~
towns.cpp:75:17: warning: conversion to 'int' from 'std::vector<int>::size_type {aka long unsigned int}' may alter its value [-Wconversion]
  int sz = v.size();
           ~~~~~~^~
towns.cpp:28:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int n, int sub) {
                            ^~~
# Verdict Execution time Memory Grader output
1 Correct 35 ms 632 KB Output is correct
2 Correct 34 ms 632 KB Output is correct
3 Correct 2 ms 672 KB Output is correct
4 Correct 30 ms 808 KB Output is correct
5 Correct 27 ms 808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 808 KB Output is correct
2 Correct 20 ms 808 KB Output is correct
3 Correct 29 ms 808 KB Output is correct
4 Correct 30 ms 908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 46 ms 908 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 26 ms 912 KB Output isn't correct
2 Halted 0 ms 0 KB -