Submission #60651

# Submission time Handle Problem Language Result Execution time Memory
60651 2018-07-24T13:10:19 Z reality Towns (IOI15_towns) C++17
23 / 100
32 ms 900 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;
	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));
	for (auto it : s)
		if (max(it,get(x,y) - it) == ans) {
			dist = it;
			break;
		}
	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;
	auto ok = [&](int A,int B) {
		return get(A,B) != get(A,x) + get(B,x) - 2 * dist;
	};
	for (int i = 0;i < n;++i)
		if (!was[i]) {
			was[i] = 1;
			int cnt = 1;
			for (int j = i + 1;cnt <= (n / 2) && j < n;++j)
				if (!was[j] && ok(i,j))
					++cnt,was[j] = 1;
			if (cnt > (n / 2))
				return -ans;
		}
	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:28:28: warning: unused parameter 'sub' [-Wunused-parameter]
 int hubDistance(int n, int sub) {
                            ^~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 760 KB Output is correct
2 Correct 26 ms 760 KB Output is correct
3 Correct 3 ms 760 KB Output is correct
4 Correct 30 ms 760 KB Output is correct
5 Correct 26 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 24 ms 900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 900 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 17 ms 900 KB Output isn't correct
2 Halted 0 ms 0 KB -