Submission #1046180

# Submission time Handle Problem Language Result Execution time Memory
1046180 2024-08-06T11:12:42 Z ksun69(#11074) Ancient Machine 2 (JOI23_ancient2) C++17
99 / 100
26 ms 840 KB
#include "ancient2.h"
#include <bits/stdc++.h>

namespace {
	using namespace std;

	const int S = 1000;
	using bs = bitset<S>;
	string my_solve(int N){
		int M = 106;
		int nq = 0;
		vector<bs> basis(S);
		vector<int> result(S, 0);
		int rank = 0;

		for(int i = 0; i + 3 <= M; i++){
			if(basis[i].any()) continue;
			int Q = i + 3;
			vector<int> A(Q), B(Q);
			for(int j = 0; j < i; j++){
				A[j] = B[j] = j+1;
			}
			A[i] = i+1;
			B[i] = i+2;
			A[i+1] = B[i+1] = i+1;
			A[i+2] = B[i+2] = i+2;
			int res = Query(Q, A, B);
			basis[i][i] = 1;
			result[i] = res - (i+1);
			rank++;
		}
		for(int c = 0; c < M/2; c++){
			int Q = 2 * (M/2);
			vector<int> A(Q), B(Q);
			for(int i = 0; i < M/2; i++){
				A[2*i] = (2*i+2) % Q;
				A[2*i+1] = (2*i+3) % Q;
				B[2*i] = (2*i+2) % Q;
				B[2*i+1] = (2*i+3) % Q;
			}
			A[2*c] = A[2*c+1] = (2*c+2) % Q;
			B[2*c] = B[2*c+1] = (2*c+3) % Q;
			int res = Query(Q, A, B);
			// s < S, s = c mod (M/2)

			int idx = c + (M/2) * ((S-1-c) / (M/2));
			if(basis[idx].any()) continue;
			basis[idx][idx] = 1;
			result[idx] = res % 2;
			rank++;
		}

		for(int L = M/2; L > 0; L--){
			for(int d = 0; d < L; d++){
				if(nq >= S) break;
				bs mask;
				for(int x = d; x < S; x += L) mask[x] = 1;

				bs r = mask;
				int b;
				int prev_result = 0;
				for(b = 0; b < S; b++){
					if(r[b]){
						r ^= basis[b];
						prev_result ^= result[b];
					}
					if(r[b] && !basis[b].any()){
						basis[b] = r;
						break;
					}
				}
				if(!r.any()) continue;
				rank++;
				nq++;
				int Q = L*2;
				vector<int> A(Q), B(Q);
				for(int i = 0; i < L; i++){
					int nxt = (i+1) % L;
					if(i == d){
						A[2*i] = 2*nxt;
						A[2*i+1] = 2*nxt+1;
						B[2*i] = 2*nxt+1;
						B[2*i+1] = 2*nxt;
					} else {
						A[2*i] = 2*nxt;
						A[2*i+1] = 2*nxt+1;
						B[2*i] = 2*nxt;
						B[2*i+1] = 2*nxt+1;
					}
				}
				int res = Query(Q, A, B);
				result[b] = (res % 2) ^ prev_result;
			}
		}

		string ans(N, '0');
		for(int i = N-1; i >= 0; i--){
			int v = result[i];
			for(int j = 0; j < N; j++){
				if(ans[j] == '1' && basis[i][j]) v ^= 1;
			}
			ans[i] = '0' + v;
		}
		cerr << "rank = " << rank << '\n';
		cerr << ans << '\n';
		return ans;
	}

}  // namespace

std::string Solve(int N) {
	return my_solve(N);
}
# Verdict Execution time Memory Grader output
1 Partially correct 23 ms 560 KB Output is partially correct
2 Partially correct 25 ms 588 KB Output is partially correct
3 Partially correct 15 ms 344 KB Output is partially correct
4 Partially correct 15 ms 344 KB Output is partially correct
5 Partially correct 21 ms 344 KB Output is partially correct
6 Partially correct 26 ms 344 KB Output is partially correct
7 Partially correct 20 ms 584 KB Output is partially correct
8 Partially correct 15 ms 344 KB Output is partially correct
9 Partially correct 22 ms 576 KB Output is partially correct
10 Partially correct 24 ms 584 KB Output is partially correct
11 Partially correct 21 ms 564 KB Output is partially correct
12 Partially correct 15 ms 592 KB Output is partially correct
13 Partially correct 17 ms 600 KB Output is partially correct
14 Partially correct 15 ms 344 KB Output is partially correct
15 Partially correct 18 ms 588 KB Output is partially correct
16 Partially correct 15 ms 592 KB Output is partially correct
17 Partially correct 15 ms 344 KB Output is partially correct
18 Partially correct 15 ms 344 KB Output is partially correct
19 Partially correct 24 ms 564 KB Output is partially correct
20 Partially correct 16 ms 588 KB Output is partially correct
21 Partially correct 15 ms 344 KB Output is partially correct
22 Partially correct 15 ms 564 KB Output is partially correct
23 Partially correct 15 ms 588 KB Output is partially correct
24 Partially correct 15 ms 344 KB Output is partially correct
25 Partially correct 15 ms 344 KB Output is partially correct
26 Partially correct 15 ms 344 KB Output is partially correct
27 Partially correct 16 ms 580 KB Output is partially correct
28 Partially correct 15 ms 344 KB Output is partially correct
29 Partially correct 15 ms 580 KB Output is partially correct
30 Partially correct 15 ms 344 KB Output is partially correct
31 Partially correct 15 ms 344 KB Output is partially correct
32 Partially correct 20 ms 840 KB Output is partially correct
33 Partially correct 15 ms 564 KB Output is partially correct
34 Partially correct 15 ms 344 KB Output is partially correct
35 Partially correct 18 ms 600 KB Output is partially correct
36 Partially correct 15 ms 344 KB Output is partially correct
37 Partially correct 20 ms 344 KB Output is partially correct
38 Partially correct 17 ms 592 KB Output is partially correct
39 Partially correct 15 ms 344 KB Output is partially correct
40 Partially correct 15 ms 344 KB Output is partially correct
41 Partially correct 15 ms 564 KB Output is partially correct
42 Partially correct 16 ms 600 KB Output is partially correct
43 Partially correct 17 ms 600 KB Output is partially correct
44 Partially correct 15 ms 340 KB Output is partially correct
45 Partially correct 22 ms 344 KB Output is partially correct
46 Partially correct 15 ms 580 KB Output is partially correct
47 Partially correct 15 ms 592 KB Output is partially correct
48 Partially correct 19 ms 592 KB Output is partially correct
49 Partially correct 15 ms 344 KB Output is partially correct
50 Partially correct 15 ms 592 KB Output is partially correct
51 Partially correct 15 ms 344 KB Output is partially correct
52 Partially correct 24 ms 344 KB Output is partially correct
53 Partially correct 15 ms 344 KB Output is partially correct
54 Partially correct 15 ms 344 KB Output is partially correct
55 Partially correct 15 ms 588 KB Output is partially correct
56 Partially correct 15 ms 588 KB Output is partially correct
57 Partially correct 21 ms 580 KB Output is partially correct
58 Partially correct 15 ms 344 KB Output is partially correct
59 Partially correct 18 ms 584 KB Output is partially correct
60 Partially correct 15 ms 344 KB Output is partially correct
61 Partially correct 15 ms 588 KB Output is partially correct
62 Partially correct 14 ms 344 KB Output is partially correct
63 Partially correct 15 ms 592 KB Output is partially correct