#include "ancient2.h"
#include <bits/stdc++.h>
using namespace std;
#define all(arr) (arr).begin(), (arr).end()
#define ll long long
#define ld long double
#define pb push_back
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define endl '\n'
const int N = 1000, LB = 100, UB = 898;
bitset<N> basisx[N], basisy[N];
bool res[N], val[N];
vector<pair<int, int>> pairs;
void try_add(int q, int p){
bitset<N> curx, cury;
for (int i = q; i < N; i += p) curx.set(i);
for (int i = UB; i >= LB; i--){
if (!curx.test(i)) continue;
if (!basisx[i].any()){
cury.set(sz(pairs));
pairs.pb({q, p});
basisx[i] = curx, basisy[i] = cury;
return;
}
curx ^= basisx[i], cury ^= basisy[i];
}
}
void precalc(){
for (int p = 1;; p++){
for (int q = 0; q < p; q++){
try_add(q, p);
if (sz(pairs) == UB - LB + 1) return;
}
}
}
vector<int> prefix_function(string s){
int n = sz(s);
vector<int> pi(n);
for (int i = 1; i < n; i++){
int k = pi[i - 1];
while (k && s[k] != s[i]) k = pi[k - 1];
pi[i] = k + (s[i] == s[k]);
}
return pi;
}
vector<vector<int>> build_automaton(string s){
auto pi = prefix_function(s);
int n = sz(s);
vector<vector<int>> aut(2, vector<int>(n + 1));
for (int i = 0; i <= n; i++){
for (int c = 0; c < 2; c++){
if (s[i] == '0' + c) aut[c][i] = i + 1;
else if (i) aut[c][i] = aut[c][pi[i - 1]];
}
}
return aut;
}
std::string Solve(int n) {
precalc();
for (int i = 0; i < sz(pairs); i++){
auto [q, p] = pairs[i];
vector<int> a(2 * p), b(2 * p);
iota(all(a), 1);
iota(all(b), 1);
a[p - 1] = 0, a[2 * p - 1] = p;
b[p - 1] = 0, b[2 * p - 1] = p;
b[q] = p + (q + 1) % p, b[p + q] = (q + 1) % p;
res[i] = (Query(2 * p, a, b) >= p);
}
for (int i = 0; i < LB; i++){
vector<int> a(i + 3), b(i + 3);
iota(all(a), 1);
iota(all(b), 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;
val[i] = (Query(sz(a), a, b) == i + 2);
}
string t;
for (int i = n - 1; i > UB; i--){
auto aut = build_automaton("0" + t);
t = (Query(sz(aut[0]), aut[0], aut[1]) == sz(t) + 1? "0" : "1") + t;
val[i] = t[0] - '0';
}
for (int i = 0; i < sz(pairs); i++){
for (int j = 0; j < n; j++){
if ((j < LB || j > UB) && j % pairs[i].se == pairs[i].fi) res[i] ^= val[j];
}
}
for (int i = LB; i <= UB; i++){
for (int j = 0; j < sz(pairs); j++){
if (basisy[i].test(j)) val[i] ^= res[j];
}
for (int j = LB; j < i; j++){
if (basisx[i].test(j)) val[i] ^= val[j];
}
}
string ans;
for (int i = 0; i < n; i++) ans.pb(val[i] + '0');
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
464 KB |
Output is correct |
2 |
Correct |
27 ms |
528 KB |
Output is correct |
3 |
Correct |
27 ms |
528 KB |
Output is correct |
4 |
Correct |
29 ms |
528 KB |
Output is correct |
5 |
Correct |
27 ms |
528 KB |
Output is correct |
6 |
Correct |
34 ms |
536 KB |
Output is correct |
7 |
Correct |
27 ms |
536 KB |
Output is correct |
8 |
Correct |
30 ms |
528 KB |
Output is correct |
9 |
Correct |
27 ms |
464 KB |
Output is correct |
10 |
Correct |
29 ms |
540 KB |
Output is correct |
11 |
Correct |
26 ms |
532 KB |
Output is correct |
12 |
Correct |
35 ms |
512 KB |
Output is correct |
13 |
Correct |
27 ms |
464 KB |
Output is correct |
14 |
Correct |
30 ms |
528 KB |
Output is correct |
15 |
Correct |
29 ms |
532 KB |
Output is correct |
16 |
Correct |
29 ms |
528 KB |
Output is correct |
17 |
Correct |
31 ms |
524 KB |
Output is correct |
18 |
Correct |
30 ms |
528 KB |
Output is correct |
19 |
Correct |
30 ms |
524 KB |
Output is correct |
20 |
Correct |
29 ms |
524 KB |
Output is correct |
21 |
Correct |
30 ms |
540 KB |
Output is correct |
22 |
Correct |
29 ms |
528 KB |
Output is correct |
23 |
Correct |
25 ms |
540 KB |
Output is correct |
24 |
Correct |
28 ms |
532 KB |
Output is correct |
25 |
Correct |
30 ms |
524 KB |
Output is correct |
26 |
Correct |
26 ms |
532 KB |
Output is correct |
27 |
Correct |
28 ms |
528 KB |
Output is correct |
28 |
Correct |
31 ms |
652 KB |
Output is correct |
29 |
Correct |
33 ms |
536 KB |
Output is correct |
30 |
Correct |
27 ms |
524 KB |
Output is correct |
31 |
Correct |
27 ms |
616 KB |
Output is correct |
32 |
Correct |
29 ms |
528 KB |
Output is correct |
33 |
Correct |
24 ms |
536 KB |
Output is correct |
34 |
Correct |
30 ms |
520 KB |
Output is correct |
35 |
Correct |
30 ms |
656 KB |
Output is correct |
36 |
Correct |
32 ms |
524 KB |
Output is correct |
37 |
Correct |
35 ms |
544 KB |
Output is correct |
38 |
Correct |
29 ms |
464 KB |
Output is correct |
39 |
Correct |
31 ms |
536 KB |
Output is correct |
40 |
Correct |
24 ms |
536 KB |
Output is correct |
41 |
Correct |
29 ms |
472 KB |
Output is correct |
42 |
Correct |
29 ms |
592 KB |
Output is correct |
43 |
Correct |
30 ms |
464 KB |
Output is correct |
44 |
Correct |
24 ms |
540 KB |
Output is correct |
45 |
Correct |
29 ms |
532 KB |
Output is correct |
46 |
Correct |
29 ms |
528 KB |
Output is correct |
47 |
Correct |
34 ms |
464 KB |
Output is correct |
48 |
Correct |
27 ms |
464 KB |
Output is correct |
49 |
Correct |
32 ms |
528 KB |
Output is correct |
50 |
Correct |
28 ms |
532 KB |
Output is correct |
51 |
Correct |
30 ms |
640 KB |
Output is correct |
52 |
Correct |
29 ms |
528 KB |
Output is correct |
53 |
Correct |
34 ms |
536 KB |
Output is correct |
54 |
Correct |
28 ms |
524 KB |
Output is correct |
55 |
Correct |
33 ms |
464 KB |
Output is correct |
56 |
Correct |
27 ms |
516 KB |
Output is correct |
57 |
Correct |
35 ms |
532 KB |
Output is correct |
58 |
Correct |
28 ms |
528 KB |
Output is correct |
59 |
Correct |
33 ms |
516 KB |
Output is correct |
60 |
Correct |
33 ms |
520 KB |
Output is correct |
61 |
Correct |
32 ms |
516 KB |
Output is correct |
62 |
Correct |
29 ms |
536 KB |
Output is correct |
63 |
Correct |
29 ms |
532 KB |
Output is correct |