#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;
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;
}
}
// DBG(U); DBG(V);
// ok now you just want the midpoint of the diameter
//i think this is enough information!
ans = INF;
FOR(i, 0, N)
{
int du = ask(U, i), dv = ask(V, i);
if (du == dv + D || dv == du + D) continue;
int da = (du - dv + D) / 2, db = (dv - du + D) / 2;
ckmin(ans, max(da, db));
}
cout << ans << '\n';
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:154:1: warning: no return statement in function returning non-void [-Wreturn-type]
}
^
towns.cpp:115:28: warning: unused parameter 'subtask' [-Wunused-parameter]
int hubDistance(int n, int subtask)
^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
1176 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
1872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
18 ms |
2652 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
22 ms |
3492 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
4020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
4464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |