Submission #88146

#TimeUsernameProblemLanguageResultExecution timeMemory
88146qkxwsmTowns (IOI15_towns)C++14
25 / 100
21 ms2132 KiB
#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, T; int ans; int id[MAXN]; 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]; } bool check(int a, int b) { //intersection of U-T to U-V if (id[a] < 0 || id[b] < 0) { return id[a] == id[b]; } return (id[a] + id[b] != ask(a, b)); } 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; int da = (du + DU - d0 + L) / 2; ckmin(ans, max(da, D - da)); } return ans; int lt = -1, rt = -1; if (DU == ans) rt = 0; if (DV == ans) lt = 0; FOR(i, 0, N) { int d0 = ask(0, i), du = ask(U, i); if (d0 - du <= L - DU) continue; int da = (du + DU - d0 + L) / 2; if (da == ans) rt = i; if (D - da == ans) lt = i; } if (lt != -1 && rt != -1) { if (lt == rt) { rt = -1; } else { int lts, rts; FOR(i, 0, N) { int d0 = ask(0, i), du = ask(U, i); if (d0 - du <= L - DU) { rts++; } else { int da = (du + DU - d0 + L) / 2; if (da <= D - ans) lts++; else rts++; } } if (lts == rts) return ans; if (lts > rts) rt = -1; else lt = -1; } } T = (lt == -1 ? rt : lt); //you're trying to see if the one @T will be good DV = (ask(T, U) - ask(T, V) + D) / 2; FOR(i, 0, N) id[i] = 0; FOR(i, 0, N) { int d0 = ask(0, i), du = ask(U, i); if (d0 - du <= L - DU) continue; int da = (du + DU - d0 + L) / 2; if (da < DV) id[i] = -1; } FOR(i, 0, N) { if (id[i] == -1) continue; id[i] = ask(U, i) - DV; } // FOR(i, 0, N) // { // cerr << id[i] << ' '; // } // cerr << endl; //lol... int maj = -1, cnt = 0; FOR(i, 0, N) { if (cnt == 0) { maj = i; } if (check(i, maj)) cnt++; else cnt--; } cnt = 0; FOR(i, 0, N) { if (check(maj, i)) cnt++; } return (cnt * 2 > N ? -ans : ans); }

Compilation message (stderr)

towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:125:28: warning: unused parameter 'subtask' [-Wunused-parameter]
 int hubDistance(int n, int subtask)
                            ^~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...