답안 #1002401

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1002401 2024-06-19T14:17:36 Z zsombor Ancient Machine 2 (JOI23_ancient2) C++17
97 / 100
38 ms 836 KB
#include "ancient2.h"
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;

int n, m = 0;
vector <int> ans(1e3, -1);
vector <bitset <1001>> v(1e3);

void get1(int x) {
	vector <int> a(x + 3, 0);
	vector <int> b(x + 3, 0);
	for (int i = 0; i < x; i++) a[i] = b[i] = i + 1;
	a[x] = x + 1;
	b[x] = x + 2;
	a[x + 1] = b[x + 1] = x + 1;
	a[x + 2] = b[x + 2] = x + 2;
	ans[x] = Query(x + 3, a, b) - x - 1;
}

void solve1() {
	for (int i = 0; i < m - 2; i++) get1(i);
}

void get2(int x) {
	vector <int> s(1, -1);
	s.push_back(1);
	for (int i = x + 1; i < n; i++) s.push_back(ans[i]);
	s.push_back(-1);
	int l = s.size() - 2;

	vector <int> pi(l + 1, 0);
	pi[0] = -1;
	for (int i = 1; i <= l; i++) {
		for (int j = pi[i - 1]; j >= 0; j = pi[j]) {
			if (s[i] == s[j + 1]) { pi[i] = j + 1; break; }
		}
	}

	vector <int> a(l + 1, 0);
	vector <int> b(l + 1, 1);
	for (int i = 1; i <= l; i++) {
		a[i] = (s[i + 1] == 0 ? i + 1 : a[pi[i]]);
		b[i] = (s[i + 1] == 1 ? i + 1 : b[pi[i]]);
	}
	ans[x] = (Query(l + 1, a, b) == l);
}

void solve2() {
	for (int i = n - 1; i > n - m; i--) get2(i);
}

int make_query(int p, int q) {
	vector <int> a(2 * p, 0);
	vector <int> b(2 * p, 0);
	for (int i = 0; i < 2 * p; i++) a[i] = b[i] = (i + 1) % p + i / p * p;
	swap(b[q], b[p + q]);
	return (Query(2 * p, a, b) >= p);
}

void try_add(int p, int q) {
	bitset <1001> b;
	for (int i = 0; i < n; i++) b[i] = int(i % p == q);
	b[1000] = 0;
	for (int i = 0; i < n; i++) if (b[i]) b ^= v[i];

	int k = -1;
	for (int i = 0; i < n; i++) if (b[i]) k = i;
	if (k == -1) return;

	b[1000] = int(b[1000]) ^ make_query(p, q);
	for (int i = 0; i < n; i++) if (v[i][k]) v[i] ^= b;
	v[k] = b;
}

void solve3() {
	for (int i = 0; i < n; i++) {
		if (ans[i] == -1) continue;
		v[i][i] = 1;
		v[i][1000] = ans[i];
	}
	for (int i = 1; i <= 60; i++) {
		for (int j = 0; j < i; j++) {
			try_add(i, j);
		}
	}
	for (int i = 0; i < n; i++) ans[i] = v[i][1000];
}

string Solve(int N) {
	n = N;
	solve1();
	solve2();
	solve3();
	string s;
	for (int i = 0; i < n; i++) s.push_back('0' + ans[i]);
	return s;
}
# 결과 실행 시간 메모리 Grader output
1 Partially correct 23 ms 580 KB Output is partially correct
2 Partially correct 28 ms 572 KB Output is partially correct
3 Partially correct 23 ms 556 KB Output is partially correct
4 Partially correct 23 ms 344 KB Output is partially correct
5 Partially correct 23 ms 600 KB Output is partially correct
6 Partially correct 31 ms 592 KB Output is partially correct
7 Partially correct 31 ms 592 KB Output is partially correct
8 Partially correct 24 ms 344 KB Output is partially correct
9 Partially correct 28 ms 344 KB Output is partially correct
10 Partially correct 24 ms 596 KB Output is partially correct
11 Partially correct 23 ms 600 KB Output is partially correct
12 Partially correct 27 ms 600 KB Output is partially correct
13 Partially correct 23 ms 344 KB Output is partially correct
14 Partially correct 24 ms 832 KB Output is partially correct
15 Partially correct 24 ms 344 KB Output is partially correct
16 Partially correct 23 ms 340 KB Output is partially correct
17 Partially correct 23 ms 580 KB Output is partially correct
18 Partially correct 25 ms 600 KB Output is partially correct
19 Partially correct 29 ms 604 KB Output is partially correct
20 Partially correct 24 ms 344 KB Output is partially correct
21 Partially correct 29 ms 572 KB Output is partially correct
22 Partially correct 24 ms 564 KB Output is partially correct
23 Partially correct 24 ms 836 KB Output is partially correct
24 Partially correct 28 ms 604 KB Output is partially correct
25 Partially correct 30 ms 600 KB Output is partially correct
26 Partially correct 23 ms 340 KB Output is partially correct
27 Partially correct 26 ms 600 KB Output is partially correct
28 Partially correct 31 ms 344 KB Output is partially correct
29 Partially correct 24 ms 344 KB Output is partially correct
30 Partially correct 25 ms 600 KB Output is partially correct
31 Partially correct 25 ms 568 KB Output is partially correct
32 Partially correct 32 ms 600 KB Output is partially correct
33 Partially correct 23 ms 600 KB Output is partially correct
34 Partially correct 23 ms 796 KB Output is partially correct
35 Partially correct 36 ms 824 KB Output is partially correct
36 Partially correct 24 ms 600 KB Output is partially correct
37 Partially correct 29 ms 592 KB Output is partially correct
38 Partially correct 28 ms 576 KB Output is partially correct
39 Partially correct 37 ms 344 KB Output is partially correct
40 Partially correct 26 ms 592 KB Output is partially correct
41 Partially correct 26 ms 568 KB Output is partially correct
42 Partially correct 24 ms 576 KB Output is partially correct
43 Partially correct 34 ms 580 KB Output is partially correct
44 Partially correct 24 ms 580 KB Output is partially correct
45 Partially correct 25 ms 600 KB Output is partially correct
46 Partially correct 23 ms 344 KB Output is partially correct
47 Partially correct 23 ms 344 KB Output is partially correct
48 Partially correct 23 ms 344 KB Output is partially correct
49 Partially correct 38 ms 344 KB Output is partially correct
50 Partially correct 23 ms 344 KB Output is partially correct
51 Partially correct 23 ms 600 KB Output is partially correct
52 Partially correct 31 ms 600 KB Output is partially correct
53 Partially correct 25 ms 572 KB Output is partially correct
54 Partially correct 24 ms 564 KB Output is partially correct
55 Partially correct 23 ms 600 KB Output is partially correct
56 Partially correct 23 ms 828 KB Output is partially correct
57 Partially correct 24 ms 572 KB Output is partially correct
58 Partially correct 28 ms 584 KB Output is partially correct
59 Partially correct 24 ms 592 KB Output is partially correct
60 Partially correct 29 ms 572 KB Output is partially correct
61 Partially correct 25 ms 600 KB Output is partially correct
62 Partially correct 25 ms 580 KB Output is partially correct
63 Partially correct 28 ms 600 KB Output is partially correct