답안 #817083

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
817083 2023-08-09T09:18:14 Z rainboy Ancient Machine 2 (JOI23_ancient2) C++17
100 / 100
37 ms 724 KB
/* upsolved with help from GusterGoose27 */
#include "ancient2.h"
#include <cstring>
#include <vector>

using namespace std;

typedef unsigned long long ull;
typedef vector<int> vi;

const int N = 1000, M = 102, L = 64, K = (N + L - 1) / L;

ull vvv[N][K]; int ww[N];

int add(ull *vv) {
	int w = 0;
	for (int i = 0; i < N; i++)
		if ((vv[i / L] & 1ULL << i % L) != 0) {
			if ((vvv[i][i / L] & 1ULL << i % L) != 0) {
				for (int h = i / L; h < K; h++)
					vv[h] ^= vvv[i][h];
				w ^= ww[i];
			} else {
				for (int h = i / L; h < K; h++)
					vvv[i][h] = vv[h];
				ww[i] = w;
				return i;
			}
		}
	return -1;
}

string Solve(int n) {
	string cc(N, '0');
	ull vv[K];
	int rank = 0;
	for (int i = 0; i + 3 <= M; i++) {
		memset(vv, 0, K * sizeof *vv), vv[i / L] |= 1ULL << i % L;
		add(vv), rank++;
		int m = i + 3;
		vi aa(m), bb(m);
		for (int s = 0; s < i; s++)
			aa[s] = bb[s] = s + 1;
		aa[i] = i + 1, bb[i] = i + 2;
		aa[i + 1] = bb[i + 1] = i + 1;
		aa[i + 2] = bb[i + 2] = i + 2;
		if (Query(m, aa, bb) != i + 1)
			ww[i] ^= 1;
	}
	for (int i = N - 1; N - i + 1 <= M; i--) {
		memset(vv, 0, K * sizeof *vv), vv[i / L] |= 1ULL << i % L;
		add(vv), rank++;
		cc[i] = '0';
		int m = N - i + 1;
		vi aa(m), bb(m);
		int f = -1;
		for (int s = 0; s + 1 < m; s++) {
			if (cc[i + s] == '0')
				aa[s] = s + 1, bb[s] = f == -1 ? 0 : bb[f];
			else
				aa[s] = f == -1 ? 0 : aa[f], bb[s] = s + 1;
			f = f == -1 ? 0 : (cc[i + s] == '0' ? aa[f] : bb[f]);
		}
		aa[m - 1] = aa[f], bb[m - 1] = bb[f];
		if (Query(m, aa, bb) != m - 1)
			ww[i] ^= 1, cc[i] = '1';
	}
	for (int c = 1; c * 2 <= M; c++) {
		int m = c * 2;
		vi aa(m), bb(m);
		for (int r = 0; r < c; r++) {
			memset(vv, 0, K * sizeof *vv);
			for (int i = 0; i < N; i++)
				if (i % c == r)
					vv[i / L] |= 1ULL << i % L;
			int i = add(vv);
			if (i != -1) {
				rank++;
				for (int s = 0; s < c; s++) {
					aa[s] = bb[s] = (s + 1) % c;
					aa[c + s] = bb[c + s] = c + (s + 1) % c;
				}
				bb[r] = c + (r + 1) % c;
				bb[c + r] = (r + 1) % c;
				if (Query(m, aa, bb) >= c)
					ww[i] ^= 1;
			}
		}
	}
	if (rank != N)
		return ":(";
	for (int i = N - 1; i >= 0; i--) {
		for (int j = i + 1; j < N; j++)
			if ((vvv[i][j / L] & 1ULL << j % L) != 0)
				ww[i] ^= ww[j];
		cc[i] = ww[i] + '0';
	}
	return cc;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 724 KB Output is correct
2 Correct 27 ms 356 KB Output is correct
3 Correct 32 ms 408 KB Output is correct
4 Correct 33 ms 328 KB Output is correct
5 Correct 29 ms 336 KB Output is correct
6 Correct 30 ms 364 KB Output is correct
7 Correct 36 ms 376 KB Output is correct
8 Correct 26 ms 404 KB Output is correct
9 Correct 37 ms 392 KB Output is correct
10 Correct 33 ms 396 KB Output is correct
11 Correct 36 ms 368 KB Output is correct
12 Correct 32 ms 380 KB Output is correct
13 Correct 30 ms 412 KB Output is correct
14 Correct 30 ms 376 KB Output is correct
15 Correct 27 ms 364 KB Output is correct
16 Correct 34 ms 388 KB Output is correct
17 Correct 33 ms 396 KB Output is correct
18 Correct 29 ms 388 KB Output is correct
19 Correct 37 ms 384 KB Output is correct
20 Correct 31 ms 336 KB Output is correct
21 Correct 30 ms 408 KB Output is correct
22 Correct 29 ms 336 KB Output is correct
23 Correct 32 ms 352 KB Output is correct
24 Correct 32 ms 384 KB Output is correct
25 Correct 35 ms 384 KB Output is correct
26 Correct 26 ms 412 KB Output is correct
27 Correct 31 ms 416 KB Output is correct
28 Correct 30 ms 352 KB Output is correct
29 Correct 33 ms 400 KB Output is correct
30 Correct 32 ms 408 KB Output is correct
31 Correct 34 ms 384 KB Output is correct
32 Correct 32 ms 336 KB Output is correct
33 Correct 32 ms 380 KB Output is correct
34 Correct 29 ms 404 KB Output is correct
35 Correct 29 ms 376 KB Output is correct
36 Correct 33 ms 348 KB Output is correct
37 Correct 29 ms 420 KB Output is correct
38 Correct 35 ms 496 KB Output is correct
39 Correct 32 ms 480 KB Output is correct
40 Correct 30 ms 360 KB Output is correct
41 Correct 37 ms 368 KB Output is correct
42 Correct 37 ms 336 KB Output is correct
43 Correct 35 ms 340 KB Output is correct
44 Correct 31 ms 364 KB Output is correct
45 Correct 36 ms 352 KB Output is correct
46 Correct 31 ms 336 KB Output is correct
47 Correct 33 ms 380 KB Output is correct
48 Correct 35 ms 360 KB Output is correct
49 Correct 32 ms 344 KB Output is correct
50 Correct 29 ms 400 KB Output is correct
51 Correct 29 ms 372 KB Output is correct
52 Correct 30 ms 308 KB Output is correct
53 Correct 32 ms 488 KB Output is correct
54 Correct 36 ms 336 KB Output is correct
55 Correct 31 ms 380 KB Output is correct
56 Correct 30 ms 368 KB Output is correct
57 Correct 32 ms 336 KB Output is correct
58 Correct 32 ms 308 KB Output is correct
59 Correct 27 ms 396 KB Output is correct
60 Correct 33 ms 380 KB Output is correct
61 Correct 34 ms 400 KB Output is correct
62 Correct 26 ms 412 KB Output is correct
63 Correct 32 ms 340 KB Output is correct