Submission #1002303

# Submission time Handle Problem Language Result Execution time Memory
1002303 2024-06-19T12:19:06 Z zsombor Ancient Machine 2 (JOI23_ancient2) C++17
37 / 100
51 ms 1092 KB
#include "ancient2.h"
#include <iostream>
#include <string>
#include <vector>
#include <bitset>
using namespace std;

int n, m;
vector <int> ans(1e3, -1);

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--) if (ans[i] == -1) get2(i);
}

string Solve(int N) {
	n = N;
	m = n / 2 + 2;
	solve1();
	solve2();
	string s;
	for (int i = 0; i < n; i++) s.push_back('0' + ans[i]);
	return s;
}
# Verdict Execution time Memory Grader output
1 Partially correct 29 ms 344 KB Output is partially correct
2 Partially correct 30 ms 604 KB Output is partially correct
3 Partially correct 29 ms 572 KB Output is partially correct
4 Partially correct 47 ms 592 KB Output is partially correct
5 Partially correct 35 ms 600 KB Output is partially correct
6 Partially correct 35 ms 1092 KB Output is partially correct
7 Partially correct 27 ms 592 KB Output is partially correct
8 Partially correct 38 ms 592 KB Output is partially correct
9 Partially correct 28 ms 592 KB Output is partially correct
10 Partially correct 39 ms 564 KB Output is partially correct
11 Partially correct 32 ms 344 KB Output is partially correct
12 Partially correct 31 ms 724 KB Output is partially correct
13 Partially correct 30 ms 576 KB Output is partially correct
14 Partially correct 32 ms 560 KB Output is partially correct
15 Partially correct 29 ms 344 KB Output is partially correct
16 Partially correct 45 ms 760 KB Output is partially correct
17 Partially correct 30 ms 600 KB Output is partially correct
18 Partially correct 31 ms 552 KB Output is partially correct
19 Partially correct 30 ms 600 KB Output is partially correct
20 Partially correct 31 ms 572 KB Output is partially correct
21 Partially correct 34 ms 592 KB Output is partially correct
22 Partially correct 35 ms 592 KB Output is partially correct
23 Partially correct 30 ms 592 KB Output is partially correct
24 Partially correct 31 ms 588 KB Output is partially correct
25 Partially correct 30 ms 572 KB Output is partially correct
26 Partially correct 29 ms 560 KB Output is partially correct
27 Partially correct 27 ms 600 KB Output is partially correct
28 Partially correct 44 ms 552 KB Output is partially correct
29 Partially correct 27 ms 344 KB Output is partially correct
30 Partially correct 28 ms 568 KB Output is partially correct
31 Partially correct 28 ms 592 KB Output is partially correct
32 Partially correct 30 ms 620 KB Output is partially correct
33 Partially correct 25 ms 572 KB Output is partially correct
34 Partially correct 30 ms 748 KB Output is partially correct
35 Partially correct 34 ms 568 KB Output is partially correct
36 Partially correct 29 ms 600 KB Output is partially correct
37 Partially correct 38 ms 580 KB Output is partially correct
38 Partially correct 39 ms 584 KB Output is partially correct
39 Partially correct 45 ms 812 KB Output is partially correct
40 Partially correct 39 ms 740 KB Output is partially correct
41 Partially correct 31 ms 568 KB Output is partially correct
42 Partially correct 28 ms 592 KB Output is partially correct
43 Partially correct 29 ms 600 KB Output is partially correct
44 Partially correct 31 ms 592 KB Output is partially correct
45 Partially correct 28 ms 572 KB Output is partially correct
46 Partially correct 30 ms 600 KB Output is partially correct
47 Partially correct 31 ms 568 KB Output is partially correct
48 Partially correct 39 ms 764 KB Output is partially correct
49 Partially correct 36 ms 668 KB Output is partially correct
50 Partially correct 31 ms 700 KB Output is partially correct
51 Partially correct 51 ms 592 KB Output is partially correct
52 Partially correct 32 ms 556 KB Output is partially correct
53 Partially correct 29 ms 592 KB Output is partially correct
54 Partially correct 36 ms 596 KB Output is partially correct
55 Partially correct 27 ms 600 KB Output is partially correct
56 Partially correct 31 ms 564 KB Output is partially correct
57 Partially correct 30 ms 592 KB Output is partially correct
58 Partially correct 30 ms 456 KB Output is partially correct
59 Partially correct 29 ms 600 KB Output is partially correct
60 Partially correct 30 ms 824 KB Output is partially correct
61 Partially correct 30 ms 600 KB Output is partially correct
62 Partially correct 30 ms 596 KB Output is partially correct
63 Partially correct 45 ms 600 KB Output is partially correct