Submission #87862

# Submission time Handle Problem Language Result Execution time Memory
87862 2018-12-02T22:38:56 Z qkxwsm Towns (IOI15_towns) C++14
25 / 100
22 ms 3836 KB
#include "towns.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

random_device(rd);
mt19937 rng(rd());
const long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();

struct custom_hash
{
	template<class T>
	unsigned long long operator()(T v) const
	{
		unsigned long long x = v;
		x += FIXED_RANDOM; x += 11400714819323198485ull;
		x = (x ^ (x >> 30)) * 13787848793156543929ull;
		x = (x ^ (x >> 27)) * 10723151780598845931ull;
		return x ^ (x >> 31);
	}
};

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T, class U> using hash_table = gp_hash_table<T, U, custom_hash>;

template<class T>
void ckmin(T &a, T b)
{
	a = min(a, b);
}
template<class T>
void ckmax(T &a, T b)
{
	a = max(a, b);
}
long long expo(long long a, long long e, long long mod)
{
	return ((e == 0) ? 1 : ((expo(a * a % mod, e >> 1, mod)) * ((e & 1) ? a : 1) % mod));
}
template<class T, class U>
T nmod(T &x, U mod)
{
	if (x >= mod) x -= mod;
}
template<class T>
T gcd(T a, T b)
{
	return (b ? gcd(b, a % b) : a);
}
template<class T>
T randomize(T mod)
{
	return (uniform_int_distribution<T>(0, mod - 1))(rng);
}

#define y0 ___y0
#define y1 ___y1
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define fi first
#define se second
#define DBG(x) cerr << #x << " = " << x << endl;
#define SZ(x) ((int) (x.size()))
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define ALL(x) x.begin(), x.end()

const long double PI = 4.0 * atan(1.0);
const long double EPS = 1e-9;

#define MAGIC 347
#define SINF 10007
#define CO 1000007
#define INF 1000000007
#define BIG 1000000931
#define LARGE 1696969696967ll
#define GIANT 2564008813937411ll
#define LLINF 2696969696969696969ll
#define MAXN 113

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdd> vpd;

int N;
int dist[MAXN][MAXN];
int U, V, D, DU, DV, L;
int ans;

int ask(int x, int y)
{
	if (x == y) return 0;
	if (dist[x][y]) return dist[x][y];
	int res = getDistance(x, y);
	dist[x][y] = res;
	dist[y][x] = res;
	return dist[x][y];
}

int hubDistance(int n, int subtask)
{
	N = n;
	FOR(i, 0, N)
	{
		FOR(j, 0, N)
		{
			dist[i][j] = 0;
		}
	}
	//find a diameter!
	D = 0;
	FOR(i, 0, N)
	{
		if (ask(0, i) > D)
		{
			D = ask(0, i); U = i;
		}
	}
	D = 0;
	FOR(i, 0, N)
	{
		if (ask(U, i) > D)
		{
			D = ask(U, i); V = i;
		}
	}
	DU = (ask(0, U) - ask(0, V) + D) / 2;
	DV = (ask(0, V) - ask(0, U) + D) / 2;
	L = (ask(0, V) + ask(0, U) - D) / 2;
	ans = max(DU, DV);
	FOR(i, 0, N)
	{
		int d0 = ask(0, i), du = ask(U, i);
		if (d0 - du <= L - DU) continue;
		// if (du - d0 - DU + L == 0)  continue;
		int da = (du + DU - d0 + L) / 2;
		ckmin(ans, max(da, D - da));
	}
	// DBG(U); DBG(V);
	// ok now you just want the midpoint of the diameter
	//i think this is enough information!
	return ans;
}

Compilation message

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:115:28: warning: unused parameter 'subtask' [-Wunused-parameter]
 int hubDistance(int n, int subtask)
                            ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 504 KB Output is correct
2 Correct 16 ms 992 KB Output is correct
3 Correct 3 ms 992 KB Output is correct
4 Correct 22 ms 1496 KB Output is correct
5 Correct 21 ms 2160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 2184 KB Output is correct
2 Correct 16 ms 2608 KB Output is correct
3 Correct 22 ms 3172 KB Output is correct
4 Correct 22 ms 3836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 3836 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3836 KB Output isn't correct
2 Halted 0 ms 0 KB -