Submission #123657

# Submission time Handle Problem Language Result Execution time Memory
123657 2019-07-01T22:44:21 Z eriksuenderhauf Highway Tolls (IOI18_highway) C++11
51 / 100
1500 ms 14532 KB
//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include "highway.h"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define mem(a,v) memset((a), (v), sizeof (a))
#define enl printf("\n")
#define case(t) printf("Case #%d: ", (t))
#define ni(n) scanf("%d", &(n))
#define nl(n) scanf("%I64d", &(n))
#define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i])
#define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i])
#define pri(n) printf("%d\n", (n))
#define prl(n) printf("%I64d\n", (n))
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vil vector<pil>
#define vll vector<pll>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef cc_hash_table<int,int,hash<int>> ht;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
const double pi = acos(-1);
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const int MAXN = 130050;
const double eps = 1e-9;
vii adj[MAXN], all;
int n, m, vis[90005], dp[2][90005], mrk[MAXN];
ll dist;

int solve(int root, int idx) {
	mem(mrk, 0);
	deque<int> pq;
	pq.pb(root);
	vi edg;
	while (!pq.empty()) {
		int u = pq.front(); pq.pop_front();
		if (dp[idx][u] < dp[idx^1][u])
			edg.pb(u);
		else if (dp[idx][u] == dp[idx^1][u] && idx)
			edg.pb(u);
		for (pii nx: adj[u]) {
			if (dp[idx][nx.fi] != dp[idx][u] + 1) continue;
			pq.pb(nx.fi);
			mrk[nx.se] = 1;
		}
	}
	vi tmp(m);
	reverse(edg.begin(), edg.end());
	for (int i = 0; i < m; i++)
		if (!mrk[i])
			tmp[i] = 1;
	int lo = 0, hi = edg.size()-1, ans = -1;
	while (lo <= hi) {
		int mi = (lo+hi) / 2;
		vi cur;
		for (int i = 0; i <= mi; i++)
			for (pii nx: adj[edg[i]])
				if (!tmp[nx.se]) {
					tmp[nx.se] = 1;
					cur.pb(nx.se);
				}
		ll w = ask(tmp);
		if (w == dist)
			lo = mi + 1;
		else {
			ans = mi;
			hi = mi - 1;
		}
		for (int i: cur)
			tmp[i] = 0;
	}
	if (ans == -1) 
		return root;
	return edg[ans];
}

void find_pair(int N, vi U, vi V, int a, int b) {
	n = N;
	m = U.size();
	for (int i = 0; i < m; i++) {
		adj[U[i]].pb(mp(V[i],i));
		adj[V[i]].pb(mp(U[i],i));
		all.pb(mp(U[i], V[i]));
	}
	dist = ask(vi(m, 0));
	int lo = 0, hi = m-1;
	while (lo <= hi) {
		int mi = (lo+hi) / 2;
		vi tmp(m);
		for (int i = 0; i <= mi; i++)
			tmp[i] = 1;
		ll w = ask(tmp);
		if (w == dist)
			lo = mi + 1;
		else
			hi = mi - 1;
	}
	int u = all[lo].fi, v = all[lo].se;
	mem(vis, 0);
	mem(dp, 0);
	deque<int> pq;
	vis[u] = 1; pq.pb(u);
	while (!pq.empty()) {
		int u2 = pq.front(); pq.pop_front();
		for (pii nx: adj[u2]) {
			if (vis[nx.fi]) continue;
			vis[nx.fi] = 1;
			dp[0][nx.fi] = dp[0][u2] + 1;
			pq.pb(nx.fi);
		}
	}
	mem(vis, 0);
	vis[v] = 1; pq.pb(v);
	while (!pq.empty()) {
		int u2 = pq.front(); pq.pop_front();
		for (pii nx: adj[u2]) {
			if (vis[nx.fi]) continue;
			vis[nx.fi] = 1;
			dp[1][nx.fi] = dp[1][u2] + 1;
			pq.pb(nx.fi);
		}
	}
	int s = solve(u, 0);
	int t = solve(v, 1);
	answer(s, t);
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 4984 KB Output is correct
2 Correct 8 ms 4928 KB Output is correct
3 Correct 6 ms 5008 KB Output is correct
4 Correct 6 ms 4856 KB Output is correct
5 Correct 6 ms 5004 KB Output is correct
6 Correct 6 ms 4856 KB Output is correct
7 Correct 6 ms 4856 KB Output is correct
8 Correct 6 ms 4916 KB Output is correct
9 Correct 6 ms 4856 KB Output is correct
10 Correct 6 ms 4856 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 4924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4980 KB Output is correct
2 Correct 35 ms 5724 KB Output is correct
3 Correct 337 ms 11860 KB Output is correct
4 Correct 310 ms 11768 KB Output is correct
5 Correct 333 ms 11756 KB Output is correct
6 Correct 273 ms 11768 KB Output is correct
7 Correct 325 ms 11824 KB Output is correct
8 Correct 436 ms 12144 KB Output is correct
9 Correct 414 ms 12096 KB Output is correct
10 Correct 303 ms 11760 KB Output is correct
11 Correct 483 ms 11256 KB Output is correct
12 Correct 404 ms 11412 KB Output is correct
13 Correct 378 ms 11476 KB Output is correct
14 Correct 433 ms 11448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 5656 KB Output is correct
2 Correct 48 ms 6328 KB Output is correct
3 Correct 70 ms 7112 KB Output is correct
4 Correct 133 ms 10972 KB Output is correct
5 Correct 174 ms 11048 KB Output is correct
6 Correct 209 ms 11292 KB Output is correct
7 Correct 183 ms 11896 KB Output is correct
8 Correct 191 ms 10852 KB Output is correct
9 Correct 197 ms 11756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 4928 KB Output is correct
2 Correct 52 ms 5680 KB Output is correct
3 Correct 306 ms 10604 KB Output is correct
4 Correct 430 ms 12104 KB Output is correct
5 Correct 381 ms 12188 KB Output is correct
6 Correct 440 ms 12212 KB Output is correct
7 Correct 423 ms 12116 KB Output is correct
8 Correct 400 ms 12112 KB Output is correct
9 Correct 412 ms 11852 KB Output is correct
10 Correct 393 ms 12032 KB Output is correct
11 Correct 381 ms 11740 KB Output is correct
12 Correct 305 ms 11424 KB Output is correct
13 Correct 425 ms 11464 KB Output is correct
14 Correct 419 ms 11072 KB Output is correct
15 Correct 415 ms 12108 KB Output is correct
16 Correct 432 ms 12184 KB Output is correct
17 Correct 381 ms 11348 KB Output is correct
18 Correct 401 ms 11560 KB Output is correct
19 Correct 404 ms 12120 KB Output is correct
20 Correct 452 ms 11884 KB Output is correct
21 Correct 222 ms 12036 KB Output is correct
22 Correct 212 ms 12036 KB Output is correct
23 Correct 249 ms 11808 KB Output is correct
24 Correct 237 ms 11500 KB Output is correct
25 Correct 309 ms 11300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 5748 KB Output is correct
2 Correct 42 ms 5880 KB Output is correct
3 Correct 318 ms 12336 KB Output is correct
4 Correct 422 ms 12736 KB Output is correct
5 Correct 503 ms 14528 KB Output is correct
6 Correct 518 ms 14532 KB Output is correct
7 Correct 528 ms 14520 KB Output is correct
8 Correct 478 ms 14520 KB Output is correct
9 Execution timed out 3064 ms 12104 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 5760 KB Output is correct
2 Correct 29 ms 5804 KB Output is correct
3 Correct 447 ms 12432 KB Output is correct
4 Correct 459 ms 12884 KB Output is correct
5 Correct 445 ms 13268 KB Output is correct
6 Partially correct 468 ms 14388 KB Output is partially correct
7 Correct 407 ms 12784 KB Output is correct
8 Correct 427 ms 13056 KB Output is correct
9 Correct 494 ms 12788 KB Output is correct
10 Correct 537 ms 14356 KB Output is correct
11 Partially correct 571 ms 14220 KB Output is partially correct
12 Correct 526 ms 13880 KB Output is correct
13 Execution timed out 3016 ms 13256 KB Time limit exceeded
14 Halted 0 ms 0 KB -