#include "ancient2.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//Autor: Michał Szeliga
#ifdef LOCAL
#define debug(...) __VA_ARGS__;
#else
#define debug(...) {}
#endif
#define read(...) debug((void)!freopen(__VA_ARGS__,"r",stdin););
const int M = 1001;
bitset<M> akt[M-1];
int ile = 0;
int gauss(bitset<M> x){
int i;
for (i = 0; i < M-1; i++){
if (x[i]){
if (!akt[i][i]){
//cout<<i<<" # "<<x<<"\n";
akt[i] = x;
ile++;
return i;
}
x ^= akt[i];
}
}
return -1;
}
bool policz(int x){
bitset<M> wy;
wy[x] = 1;
for (int i = 0; i < M-1; i++){
if (wy[i]) wy ^= akt[i];
}
return wy[M-1];
}
void stworz_automat(int c, int r){
bitset<M> wy;
for (int i = r; i < M-1; i += c) wy[i] = 1;
int id = gauss(wy);
if (id != -1){
int m = 2*c;
vector<int> A,B;
for (int i = 0; i < c; i++){
if (i%c == r){
A.push_back((r+1)%c);
B.push_back(c+(r+1)%c);
}else{
A.push_back((i+1)%c);
B.push_back((i+1)%c);
}
}
for (int i = c; i < 2*c; i++){
if (i%c == r){
A.push_back(c+(r+1)%c);
B.push_back((r+1)%c);
}else{
A.push_back(c+(i+1)%c);
B.push_back(c+(i+1)%c);
}
}
/*cout<<"Zapytanie o "<<c<<" "<<r<<"\n";
for (int j = 0; j < m; j++){
cout<<A[j]<<" "<<B[j]<<"\n";
}*/
akt[id][M-1] = akt[id][M-1]^(Query(m,A,B) >= c);
//cout<<id<<" "<<akt[id]<<"\n";
}
}
void stworz_automat2(int k){
bitset<M> wy;
wy[k] = 1;
vector<int> A,B;
for (int i = 0; i < k; i++){
A.push_back(i+1);
B.push_back(i+1);
}
A.push_back(k+1);
B.push_back(k+2);
A.push_back(k+1);
B.push_back(k+1);
A.push_back(k+2);
B.push_back(k+2);
wy[M-1] = (Query(k+3,A,B) > k+1);
gauss(wy);
}
string sufiks;
void stworz_automat3(int k){
bitset<M> wy;
wy[M-k-1] = 1;
sufiks = '0'+sufiks;
string s = '#'+sufiks+'$'+sufiks;
// cout<<s<<"\n";
int n = s.size();
int P[n+1];
P[1] = 0;
for (int i = 2; i < n; i++){
int os = P[i-1];
while (os && s[os+1] != s[i]){
os = P[os];
}
if (s[os+1] == s[i]) os++;
P[i] = os;
//cout<<i<<" "<<P[i]<<"\n";
}
vector<int> A,B;
// cout<<k+1<<"\n";
for (int i = 0; i < k+1; i++){
if (i == k || sufiks[i] == '1'){
int os = P[i+sufiks.size()+1];
while (os && s[os+1] != '0'){
os = P[os];
}
if (s[os+1] == '0') os++;
A.push_back(os);
}
if (i == k || sufiks[i] == '0'){
int os = P[i+sufiks.size()+1];
while (os && s[os+1] != '1'){
os = P[os];
}
if (s[os+1] == '1') os++;
B.push_back(os);
}
if (A.size() < B.size()) A.push_back(i+1);
if (B.size() < A.size()) B.push_back(i+1);
//cout<<A.back()<<" "<<B.back()<<"\n";
}
//exit(0);
int x = Query(k+1,A,B);
//cout<<x<<" "<<k<<"\n";
wy[M-1] = (x!=k);
//if (k == 4) exit(0);
if (wy[M-1] == 1) sufiks[0] = '1';
gauss(wy);
}
string Solve(int n){
for (int i = 0; i < 100; i++) stworz_automat2(i);
for (int i = 1; i <= 100; i++) stworz_automat3(i);
for (int c = 1; c < M-1; c++){
for (int r = 0; r < c; r++){
stworz_automat(c,r);
if (ile == M-1) break;
}
}
string wy;
for (int i = 0; i < n; i++){
if (policz(i)) wy += '1';
else wy += '0';
}
return wy;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
964 KB |
Output is correct |
2 |
Correct |
28 ms |
1444 KB |
Output is correct |
3 |
Correct |
27 ms |
2176 KB |
Output is correct |
4 |
Correct |
31 ms |
1216 KB |
Output is correct |
5 |
Correct |
31 ms |
1276 KB |
Output is correct |
6 |
Correct |
27 ms |
1024 KB |
Output is correct |
7 |
Correct |
31 ms |
1028 KB |
Output is correct |
8 |
Correct |
27 ms |
1256 KB |
Output is correct |
9 |
Correct |
27 ms |
712 KB |
Output is correct |
10 |
Correct |
26 ms |
1240 KB |
Output is correct |
11 |
Correct |
26 ms |
1476 KB |
Output is correct |
12 |
Correct |
26 ms |
1740 KB |
Output is correct |
13 |
Correct |
27 ms |
1268 KB |
Output is correct |
14 |
Correct |
27 ms |
1464 KB |
Output is correct |
15 |
Correct |
27 ms |
1508 KB |
Output is correct |
16 |
Correct |
27 ms |
1740 KB |
Output is correct |
17 |
Correct |
27 ms |
960 KB |
Output is correct |
18 |
Correct |
27 ms |
1256 KB |
Output is correct |
19 |
Correct |
28 ms |
1888 KB |
Output is correct |
20 |
Correct |
28 ms |
1720 KB |
Output is correct |
21 |
Correct |
27 ms |
1488 KB |
Output is correct |
22 |
Correct |
28 ms |
1368 KB |
Output is correct |
23 |
Correct |
28 ms |
1504 KB |
Output is correct |
24 |
Correct |
27 ms |
1536 KB |
Output is correct |
25 |
Correct |
28 ms |
1224 KB |
Output is correct |
26 |
Correct |
26 ms |
1540 KB |
Output is correct |
27 |
Correct |
28 ms |
1504 KB |
Output is correct |
28 |
Correct |
27 ms |
1528 KB |
Output is correct |
29 |
Correct |
29 ms |
1252 KB |
Output is correct |
30 |
Correct |
28 ms |
1744 KB |
Output is correct |
31 |
Correct |
26 ms |
712 KB |
Output is correct |
32 |
Correct |
26 ms |
1256 KB |
Output is correct |
33 |
Correct |
28 ms |
1772 KB |
Output is correct |
34 |
Correct |
26 ms |
1476 KB |
Output is correct |
35 |
Correct |
26 ms |
964 KB |
Output is correct |
36 |
Correct |
29 ms |
1524 KB |
Output is correct |
37 |
Correct |
27 ms |
712 KB |
Output is correct |
38 |
Correct |
26 ms |
1228 KB |
Output is correct |
39 |
Correct |
27 ms |
1484 KB |
Output is correct |
40 |
Correct |
28 ms |
1536 KB |
Output is correct |
41 |
Correct |
27 ms |
1060 KB |
Output is correct |
42 |
Correct |
27 ms |
1228 KB |
Output is correct |
43 |
Correct |
29 ms |
1532 KB |
Output is correct |
44 |
Correct |
26 ms |
1224 KB |
Output is correct |
45 |
Correct |
27 ms |
972 KB |
Output is correct |
46 |
Correct |
30 ms |
1236 KB |
Output is correct |
47 |
Correct |
27 ms |
1024 KB |
Output is correct |
48 |
Correct |
28 ms |
1388 KB |
Output is correct |
49 |
Correct |
31 ms |
1504 KB |
Output is correct |
50 |
Correct |
27 ms |
1480 KB |
Output is correct |
51 |
Correct |
27 ms |
1512 KB |
Output is correct |
52 |
Correct |
28 ms |
1728 KB |
Output is correct |
53 |
Correct |
29 ms |
1296 KB |
Output is correct |
54 |
Correct |
26 ms |
1476 KB |
Output is correct |
55 |
Correct |
26 ms |
1480 KB |
Output is correct |
56 |
Correct |
29 ms |
1480 KB |
Output is correct |
57 |
Correct |
32 ms |
1536 KB |
Output is correct |
58 |
Correct |
27 ms |
964 KB |
Output is correct |
59 |
Correct |
26 ms |
1220 KB |
Output is correct |
60 |
Correct |
26 ms |
964 KB |
Output is correct |
61 |
Correct |
26 ms |
712 KB |
Output is correct |
62 |
Correct |
30 ms |
1400 KB |
Output is correct |
63 |
Correct |
29 ms |
1280 KB |
Output is correct |