#include "ancient2.h"
#include <bits/stdc++.h>
using namespace std;
#define REP(i, j, k) for (int i = (j); i < (k); i++)
#define RREP(i, j, k) for (int i = (j); i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 1001;
const int MAXP = 51;
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
namespace {
int n;
bool findPrefix(int p) {
int m = p + 3;
vi a(m);
iota(ALL(a), 1);
a[p + 1] = p + 1;
a[p + 2] = p + 2;
vi b = a;
a[p] = p + 1;
b[p] = p + 2;
int r = Query(m, a, b);
return r == p + 2;
}
bool findSuffix(string s) {
s = "1" + s;
int n = SZ(s);
s += "?";
int m = n + 1;
vi a(m), b(m);
string ps = "";
REP (i, 0, n + 1) {
auto get = [&] (char c) {
string ts = ps + c;
REP (j, 0, SZ(ts)) {
bool pos = 1;
REP (k, 0, SZ(ts) - j) {
if (ts[j + k] != s[k]) {
pos = 0;
}
}
if (pos) {
return SZ(ts) - j;
}
}
return 0;
};
a[i] = get('0');
b[i] = get('1');
ps += s[i];
}
int r = Query(m, a, b);
return r == m - 1;
}
bool findPeriod(int p, int q) {
int m = p + p;
vi a(m);
iota(a.begin(), a.begin() + p, 1);
iota(a.begin() + p, a.begin() + m, p + 1);
a[p - 1] = 0;
a[m - 1] = p;
vi b = a;
b[q] += p;
b[q + p] -= p;
int r = Query(m, a, b);
return r >= p;
}
bitset<MAXN> basis[MAXN];
bool insert(bitset<MAXN> bs) {
REP (i, 0, MAXN) {
if (!bs[i]) {
continue;
}
if (basis[i].none()) {
basis[i] = bs;
return 1;
}
bs ^= basis[i];
}
return 0;
}
int query(bitset<MAXN> bs) {
REP (i, 0, n) {
if (!bs[i]) {
continue;
}
if (basis[i].none()) {
return -1;
}
bs ^= basis[i];
}
return bs[n];
}
}
string Solve(int N) {
n = N;
string ans(n, '0');
int rem = 1000;
REP (i, 0, min(n, 100)) {
rem--;
ans[i] = findPrefix(i) + '0';
bitset<MAXN> bs;
bs[i] = 1;
bs[n] = ans[i] - '0';
insert(bs);
}
string suf = "";
RREP (i, n - 1, max(n - 101, 1)) {
rem--;
ans[i] = findSuffix(suf) + '0';
suf = ans[i] + suf;
bitset<MAXN> bs;
bs[i] = 1;
bs[n] = ans[i] - '0';
insert(bs);
}
REP (_, 0, rem) {
int p = rnd() % MAXP + 1, q = rnd() % p;
bitset<MAXN> bs;
while (1) {
bs.reset();
for (int j = q; j < n; j += p) {
bs[j] = 1;
}
if (query(bs) == -1) {
break;
}
p = rnd() % MAXP + 1, q = rnd() % p;
}
bool b = findPeriod(p, q);
bs[n] = b;
insert(bs);
}
REP (i, min(n, 100), max(n - 101, 1)) {
bitset<MAXN> bs;
bs[i] = 1;
ans[i] = query(bs) + '0';
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
57 ms |
428 KB |
Output is correct |
2 |
Correct |
62 ms |
436 KB |
Output is correct |
3 |
Correct |
53 ms |
376 KB |
Output is correct |
4 |
Correct |
65 ms |
432 KB |
Output is correct |
5 |
Correct |
55 ms |
396 KB |
Output is correct |
6 |
Correct |
57 ms |
396 KB |
Output is correct |
7 |
Correct |
49 ms |
400 KB |
Output is correct |
8 |
Correct |
78 ms |
504 KB |
Output is correct |
9 |
Correct |
61 ms |
416 KB |
Output is correct |
10 |
Correct |
50 ms |
388 KB |
Output is correct |
11 |
Correct |
57 ms |
424 KB |
Output is correct |
12 |
Correct |
65 ms |
392 KB |
Output is correct |
13 |
Correct |
56 ms |
432 KB |
Output is correct |
14 |
Correct |
54 ms |
404 KB |
Output is correct |
15 |
Correct |
52 ms |
408 KB |
Output is correct |
16 |
Correct |
62 ms |
536 KB |
Output is correct |
17 |
Correct |
50 ms |
384 KB |
Output is correct |
18 |
Correct |
54 ms |
336 KB |
Output is correct |
19 |
Correct |
49 ms |
384 KB |
Output is correct |
20 |
Correct |
50 ms |
372 KB |
Output is correct |
21 |
Correct |
48 ms |
408 KB |
Output is correct |
22 |
Correct |
52 ms |
388 KB |
Output is correct |
23 |
Correct |
56 ms |
396 KB |
Output is correct |
24 |
Correct |
66 ms |
436 KB |
Output is correct |
25 |
Correct |
65 ms |
412 KB |
Output is correct |
26 |
Correct |
69 ms |
432 KB |
Output is correct |
27 |
Correct |
65 ms |
432 KB |
Output is correct |
28 |
Correct |
58 ms |
424 KB |
Output is correct |
29 |
Correct |
50 ms |
360 KB |
Output is correct |
30 |
Correct |
53 ms |
416 KB |
Output is correct |
31 |
Correct |
52 ms |
416 KB |
Output is correct |
32 |
Correct |
54 ms |
420 KB |
Output is correct |
33 |
Correct |
62 ms |
416 KB |
Output is correct |
34 |
Correct |
60 ms |
388 KB |
Output is correct |
35 |
Correct |
51 ms |
336 KB |
Output is correct |
36 |
Correct |
54 ms |
404 KB |
Output is correct |
37 |
Correct |
51 ms |
424 KB |
Output is correct |
38 |
Correct |
59 ms |
428 KB |
Output is correct |
39 |
Correct |
75 ms |
432 KB |
Output is correct |
40 |
Correct |
54 ms |
376 KB |
Output is correct |
41 |
Correct |
57 ms |
420 KB |
Output is correct |
42 |
Correct |
54 ms |
400 KB |
Output is correct |
43 |
Correct |
55 ms |
356 KB |
Output is correct |
44 |
Correct |
59 ms |
384 KB |
Output is correct |
45 |
Correct |
54 ms |
432 KB |
Output is correct |
46 |
Correct |
51 ms |
376 KB |
Output is correct |
47 |
Correct |
64 ms |
380 KB |
Output is correct |
48 |
Correct |
50 ms |
388 KB |
Output is correct |
49 |
Correct |
53 ms |
368 KB |
Output is correct |
50 |
Correct |
54 ms |
400 KB |
Output is correct |
51 |
Correct |
55 ms |
372 KB |
Output is correct |
52 |
Correct |
53 ms |
404 KB |
Output is correct |
53 |
Correct |
69 ms |
432 KB |
Output is correct |
54 |
Correct |
65 ms |
428 KB |
Output is correct |
55 |
Correct |
51 ms |
424 KB |
Output is correct |
56 |
Correct |
54 ms |
420 KB |
Output is correct |
57 |
Correct |
63 ms |
356 KB |
Output is correct |
58 |
Correct |
62 ms |
412 KB |
Output is correct |
59 |
Correct |
53 ms |
420 KB |
Output is correct |
60 |
Correct |
53 ms |
336 KB |
Output is correct |
61 |
Correct |
52 ms |
416 KB |
Output is correct |
62 |
Correct |
54 ms |
388 KB |
Output is correct |
63 |
Correct |
60 ms |
408 KB |
Output is correct |