# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
88470 |
2018-12-06T05:37:02 Z |
qkxwsm |
Towns (IOI15_towns) |
C++14 |
|
23 ms |
8028 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, T;
int ans;
int id[MAXN];
int lt, rt;
int maj, cnt;
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 res;
}
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];
}
if (a == b) return true;
return (id[a] + id[b] != ask(a, b));
}
int hubDistance(int n, int subtask)
{
// cerr << U << ' ' << V << ' ' << D << ' ' << DU << ' ' << DV << ' ' << L << ' ' << T << endl;
N = n; ans = 0;
FOR(i, 0, N)
{
FOR(j, 0, N)
{
dist[i][j] = 0;
}
id[i] = 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;
}
}
// cerr << U << ' ' << V << ' ' << D << ' ' << DU << ' ' << DV << ' ' << L << ' ' << T << endl;
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));
}
// cerr << DU << ' ' << DV << ' ' << L << ' ' << ans << endl;
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 == rt) rt = -1;
if (lt != -1 && rt != -1)
{
int lts = 0, rts = 0;
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;
}
// DBG(lt); DBG(rt);
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)
{
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...
// DBG(T);
vi bucket, lis;
FOR(i, 0, N)
{
if (!lis.empty() && check(lis.back(), i))
{
bucket.PB(i);
continue;
}
else
{
lis.PB(i);
if (!bucket.empty())
{
lis.PB(bucket.back());
bucket.pop_back();
}
}
}
//any two adjacent elements in lis are different!
T = bucket.back();
while(!bucket.empty() && !lis.empty())
{
int x = lis.back();
if (check(x, T))
{
lis.pop_back();
if (!lis.empty()) lis.pop_back();
}
else
{
lis.pop_back();
bucket.pop_back();
}
}
if (bucket.empty())
{
return ans;
}
else
{
return -ans;
}
// return ((cnt * 2 > N) ? -ans : ans);
}
Compilation message
towns.cpp: In function 'int hubDistance(int, int)':
towns.cpp:128:28: warning: unused parameter 'subtask' [-Wunused-parameter]
int hubDistance(int n, int subtask)
^~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3 ms |
632 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1368 KB |
Output is correct |
2 |
Correct |
17 ms |
1776 KB |
Output is correct |
3 |
Correct |
23 ms |
2432 KB |
Output is correct |
4 |
Correct |
22 ms |
2856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
3368 KB |
Output is correct |
2 |
Correct |
23 ms |
3824 KB |
Output is correct |
3 |
Correct |
2 ms |
3976 KB |
Output is correct |
4 |
Correct |
23 ms |
4380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
5172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
5656 KB |
Output is correct |
2 |
Correct |
22 ms |
6248 KB |
Output is correct |
3 |
Correct |
22 ms |
6700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
6844 KB |
Output is correct |
2 |
Correct |
23 ms |
7532 KB |
Output is correct |
3 |
Correct |
23 ms |
8028 KB |
Output is correct |