Submission #680361

# Submission time Handle Problem Language Result Execution time Memory
680361 2023-01-10T16:35:06 Z rainboy Library (JOI18_library) C++17
100 / 100
233 ms 4304 KB
#include "library.h"
#include <cstring>
#include <cstdio>
#include <vector>

using namespace std;

typedef vector<int> vi;

const int N = 1000;

int ii[N][N], kk[N], ii_[2][N], kk_[2], n;

int query(int hl, int hr, int i) {
	vi aa(n, 0);
	aa[i] = 1;
	int k = 0;
	for (int h = hl; h < hr; h++) {
		if (kk[h] == 0)
			continue;
		k++;
		for (int g = 0; g < kk[h]; g++)
			aa[ii[h][g]] = 1;
	}
	return Query(aa) != k + 1;
}

void Solve(int n_) {
	n = n_;
	for (int i = 0; i < n; i++) {
		vi aa(n, 0);
		kk_[0] = kk_[1] = 0;
		int t = 0;
		while (query(0, n, i)) {
			int lower = 0, upper = n;
			while (upper - lower > 1) {
				int h = (lower + upper) / 2;
				if (query(0, h, i))
					upper = h;
				else
					lower = h;
			}
			int h = lower;
			memcpy(ii_[t], ii[h], kk[h] * sizeof *ii[h]), kk_[t] = kk[h], kk[h] = 0;
			vi aa(n, 0);
			aa[i] = 1, aa[ii[h][0]] = 1;
			int x = Query(aa);
			if (x == 2) {
				int tmp;
				for (int h1 = 0, h2 = kk_[t] - 1; h1 < h2; h1++, h2--)
					tmp = ii_[t][h1], ii_[t][h1] = ii_[t][h2], ii_[t][h2] = tmp;
			}
			t++;
		}
		kk[i] = 0;
		for (int h = kk_[0] - 1; h >= 0; h--)
			ii[i][kk[i]++] = ii_[0][h];
		ii[i][kk[i]++] = i;
		for (int h = 0; h < kk_[1]; h++)
			ii[i][kk[i]++] = ii_[1][h];
	}
	for (int i = 0; i < n; i++)
		ii[n - 1][i]++;
	Answer(vector(ii[n - 1], ii[n - 1] + n));
}
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1008 KB # of queries: 2038
2 Correct 17 ms 1052 KB # of queries: 2026
3 Correct 30 ms 956 KB # of queries: 2134
4 Correct 28 ms 1024 KB # of queries: 2134
5 Correct 30 ms 1008 KB # of queries: 2134
6 Correct 25 ms 992 KB # of queries: 2134
7 Correct 22 ms 1028 KB # of queries: 2134
8 Correct 38 ms 1036 KB # of queries: 2050
9 Correct 27 ms 1016 KB # of queries: 2122
10 Correct 16 ms 744 KB # of queries: 1282
11 Correct 1 ms 208 KB # of queries: 1
12 Correct 1 ms 208 KB # of queries: 5
13 Correct 1 ms 208 KB # of queries: 10
14 Correct 1 ms 208 KB # of queries: 16
15 Correct 1 ms 336 KB # of queries: 98
16 Correct 3 ms 336 KB # of queries: 204
# Verdict Execution time Memory Grader output
1 Correct 30 ms 1008 KB # of queries: 2038
2 Correct 17 ms 1052 KB # of queries: 2026
3 Correct 30 ms 956 KB # of queries: 2134
4 Correct 28 ms 1024 KB # of queries: 2134
5 Correct 30 ms 1008 KB # of queries: 2134
6 Correct 25 ms 992 KB # of queries: 2134
7 Correct 22 ms 1028 KB # of queries: 2134
8 Correct 38 ms 1036 KB # of queries: 2050
9 Correct 27 ms 1016 KB # of queries: 2122
10 Correct 16 ms 744 KB # of queries: 1282
11 Correct 1 ms 208 KB # of queries: 1
12 Correct 1 ms 208 KB # of queries: 5
13 Correct 1 ms 208 KB # of queries: 10
14 Correct 1 ms 208 KB # of queries: 16
15 Correct 1 ms 336 KB # of queries: 98
16 Correct 3 ms 336 KB # of queries: 204
17 Correct 193 ms 4104 KB # of queries: 12964
18 Correct 212 ms 4240 KB # of queries: 12810
19 Correct 233 ms 4164 KB # of queries: 12964
20 Correct 165 ms 4012 KB # of queries: 12152
21 Correct 190 ms 3724 KB # of queries: 11466
22 Correct 178 ms 4180 KB # of queries: 12964
23 Correct 200 ms 4196 KB # of queries: 12950
24 Correct 86 ms 2304 KB # of queries: 6146
25 Correct 205 ms 4200 KB # of queries: 12670
26 Correct 203 ms 3912 KB # of queries: 11886
27 Correct 93 ms 2288 KB # of queries: 6120
28 Correct 219 ms 4120 KB # of queries: 12964
29 Correct 205 ms 4304 KB # of queries: 12950
30 Correct 226 ms 4112 KB # of queries: 12964