Submission #440292

# Submission time Handle Problem Language Result Execution time Memory
440292 2021-07-02T00:32:22 Z rainboy Highway Tolls (IOI18_highway) C++11
100 / 100
359 ms 9884 KB
#include "highway.h"
#include <stdlib.h>

using namespace std;

typedef vector<int> vi;

const int N = 90000, M = 130000;

int ii[M], jj[M];
int *eh[N], eo[N];

void append(int i, int h) {
	int o = eo[i]++;

	if (o >= 2 && (o & o - 1) == 0)
		eh[i] = (int *) realloc(eh[i], o * 2 * sizeof *eh[i]);
	eh[i][o] = h;
}

int hh[2][N - 1], mm[2];

void bfs(int n, int h) {
	static int cc[N], dd[N], qu[N];
	int i, head, cnt;

	for (i = 0; i < n; i++)
		dd[i] = n;
	head = cnt = 0;
	cc[ii[h]] = 0, dd[ii[h]] = 0, qu[head + cnt++] = ii[h];
	cc[jj[h]] = 1, dd[jj[h]] = 0, qu[head + cnt++] = jj[h];
	while (cnt) {
		int c, d, o;

		i = qu[cnt--, head++], c = cc[i], d = dd[i] + 1;
		for (o = eo[i]; o--; ) {
			int h = eh[i][o], j = i ^ ii[h] ^ jj[h];

			if (dd[j] > d) {
				ii[h] = i, jj[h] = j, hh[c][mm[c]++] = h;
				cc[j] = c, dd[j] = d, qu[head + cnt++] = j;
			}
		}
	}
}

void find_pair(int n, vi ii_, vi jj_, int a, int b) {
	int m = ii_.size(), h, h_, h1, i, j, c, lower, upper;
	vi ww(m, 0);
	long long d;

	for (i = 0; i < n; i++)
		eh[i] = (int *) malloc(2 * sizeof *eh[i]);
	for (h = 0; h < m; h++) {
		i = ii[h] = ii_[h], j = jj[h] = jj_[h];
		append(i, h), append(j, h);
	}
	d = ask(ww);
	lower = -1, upper = m;
	while (upper - lower > 1) {
		h_ = (lower + upper) / 2;
		for (h = 0; h < m; h++)
			ww[h] = h <= h_;
		if (ask(ww) > d)
			upper = h_;
		else
			lower = h_;
	}
	bfs(n, h1 = upper);
	for (c = 0; c < 2; c++) {
		for (h = 0; h < m; h++)
			ww[h] = 1;
		lower = -1, upper = mm[c];
		while (upper - lower > 1) {
			h_ = (lower + upper) / 2;
			for (h = 0; h < mm[c]; h++)
				ww[hh[c][h]] = h >= h_;
			for (h = 0; h < mm[c ^ 1]; h++)
				ww[hh[c ^ 1][h]] = 0;
			ww[h1] = 0;
			if (ask(ww) > d)
				lower = h_;
			else
				upper = h_;
		}
		if (lower != -1) {
			if (c == 0)
				ii[h1] = jj[hh[c][lower]];
			else
				jj[h1] = jj[hh[c][lower]];
		}
	}
	answer(ii[h1], jj[h1]);
}

Compilation message

highway.cpp: In function 'void append(int, int)':
highway.cpp:16:23: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
   16 |  if (o >= 2 && (o & o - 1) == 0)
      |                     ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 1 ms 328 KB Output is correct
5 Correct 1 ms 200 KB Output is correct
6 Correct 1 ms 200 KB Output is correct
7 Correct 1 ms 200 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 328 KB Output is correct
10 Correct 1 ms 200 KB Output is correct
11 Correct 1 ms 200 KB Output is correct
12 Correct 1 ms 200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 13 ms 1096 KB Output is correct
3 Correct 132 ms 8312 KB Output is correct
4 Correct 175 ms 8396 KB Output is correct
5 Correct 196 ms 8500 KB Output is correct
6 Correct 226 ms 8384 KB Output is correct
7 Correct 138 ms 8308 KB Output is correct
8 Correct 199 ms 8352 KB Output is correct
9 Correct 128 ms 8324 KB Output is correct
10 Correct 136 ms 8340 KB Output is correct
11 Correct 196 ms 8056 KB Output is correct
12 Correct 193 ms 8068 KB Output is correct
13 Correct 132 ms 8048 KB Output is correct
14 Correct 207 ms 8048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1116 KB Output is correct
2 Correct 24 ms 2056 KB Output is correct
3 Correct 106 ms 2872 KB Output is correct
4 Correct 193 ms 8040 KB Output is correct
5 Correct 184 ms 8160 KB Output is correct
6 Correct 109 ms 8036 KB Output is correct
7 Correct 114 ms 8120 KB Output is correct
8 Correct 210 ms 8044 KB Output is correct
9 Correct 130 ms 8040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 22 ms 1124 KB Output is correct
3 Correct 161 ms 6652 KB Output is correct
4 Correct 223 ms 8364 KB Output is correct
5 Correct 224 ms 8320 KB Output is correct
6 Correct 220 ms 8320 KB Output is correct
7 Correct 192 ms 8376 KB Output is correct
8 Correct 115 ms 8312 KB Output is correct
9 Correct 149 ms 8300 KB Output is correct
10 Correct 138 ms 8348 KB Output is correct
11 Correct 235 ms 8040 KB Output is correct
12 Correct 240 ms 8148 KB Output is correct
13 Correct 242 ms 8144 KB Output is correct
14 Correct 244 ms 8200 KB Output is correct
15 Correct 217 ms 8396 KB Output is correct
16 Correct 196 ms 8320 KB Output is correct
17 Correct 186 ms 8040 KB Output is correct
18 Correct 228 ms 8124 KB Output is correct
19 Correct 137 ms 8440 KB Output is correct
20 Correct 204 ms 8052 KB Output is correct
21 Correct 136 ms 8524 KB Output is correct
22 Correct 206 ms 8524 KB Output is correct
23 Correct 223 ms 8604 KB Output is correct
24 Correct 243 ms 8492 KB Output is correct
25 Correct 235 ms 8128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 1120 KB Output is correct
2 Correct 27 ms 1264 KB Output is correct
3 Correct 150 ms 8656 KB Output is correct
4 Correct 277 ms 9032 KB Output is correct
5 Correct 316 ms 9776 KB Output is correct
6 Correct 269 ms 9732 KB Output is correct
7 Correct 359 ms 9840 KB Output is correct
8 Correct 319 ms 9800 KB Output is correct
9 Correct 279 ms 6464 KB Output is correct
10 Correct 257 ms 6656 KB Output is correct
11 Correct 284 ms 7024 KB Output is correct
12 Correct 281 ms 8812 KB Output is correct
13 Correct 290 ms 9324 KB Output is correct
14 Correct 196 ms 9416 KB Output is correct
15 Correct 209 ms 9392 KB Output is correct
16 Correct 167 ms 7392 KB Output is correct
17 Correct 147 ms 8592 KB Output is correct
18 Correct 221 ms 8684 KB Output is correct
19 Correct 215 ms 8596 KB Output is correct
20 Correct 134 ms 8784 KB Output is correct
21 Correct 202 ms 9580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 1224 KB Output is correct
2 Correct 10 ms 1236 KB Output is correct
3 Correct 160 ms 8768 KB Output is correct
4 Correct 218 ms 8904 KB Output is correct
5 Correct 215 ms 9020 KB Output is correct
6 Correct 203 ms 9784 KB Output is correct
7 Correct 212 ms 8728 KB Output is correct
8 Correct 253 ms 8836 KB Output is correct
9 Correct 291 ms 9176 KB Output is correct
10 Correct 263 ms 9884 KB Output is correct
11 Correct 224 ms 9744 KB Output is correct
12 Correct 249 ms 9740 KB Output is correct
13 Correct 143 ms 7024 KB Output is correct
14 Correct 266 ms 6752 KB Output is correct
15 Correct 148 ms 7064 KB Output is correct
16 Correct 193 ms 6708 KB Output is correct
17 Correct 278 ms 7080 KB Output is correct
18 Correct 262 ms 6712 KB Output is correct
19 Correct 183 ms 8676 KB Output is correct
20 Correct 261 ms 9048 KB Output is correct
21 Correct 242 ms 9520 KB Output is correct
22 Correct 327 ms 9416 KB Output is correct
23 Correct 205 ms 9388 KB Output is correct
24 Correct 224 ms 9508 KB Output is correct
25 Correct 297 ms 9508 KB Output is correct
26 Correct 189 ms 9420 KB Output is correct
27 Correct 132 ms 8924 KB Output is correct
28 Correct 156 ms 8604 KB Output is correct
29 Correct 216 ms 8836 KB Output is correct
30 Correct 125 ms 8628 KB Output is correct
31 Correct 226 ms 8616 KB Output is correct
32 Correct 223 ms 8520 KB Output is correct
33 Correct 135 ms 8772 KB Output is correct
34 Correct 231 ms 8640 KB Output is correct
35 Correct 132 ms 8616 KB Output is correct
36 Correct 213 ms 8628 KB Output is correct
37 Correct 225 ms 8740 KB Output is correct
38 Correct 207 ms 8660 KB Output is correct
39 Correct 184 ms 9612 KB Output is correct
40 Correct 197 ms 9556 KB Output is correct
41 Correct 200 ms 9592 KB Output is correct
42 Correct 314 ms 9592 KB Output is correct