//bs:sanitizers,flags:grader.cpp
#include "Anna.h"
#include "Bruno.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int LEN = 145, N = LEN + 1;
bool inited = false;
ll dp[N];
int Declare() {
if (inited) {
return LEN;
}
inited = true;
dp[1] = 1;
for (int i = 3; i < N; ++i) {
dp[i] = dp[i - 2] + dp[i - 3];
}
return LEN;
}
pair<vector<int>, vector<int>> Anna(ll n) {
bool parity = n & 1;
n /= 2;
int len = 0;
while (n >= dp[len]) {
n -= dp[len];
++len;
}
vector<int> u;
while (len > 1) {
if (n >= dp[len - 2]) {
u.push_back(1);
n -= dp[len - 2];
len -= 3;
} else {
u.push_back(0);
len -= 2;
}
}
// for (int x : u) {
// cout << x << " ";
// }
// cout << endl;
vector<int> s = {1};
for (int i : u) {
if (i) {
s.push_back(s.back() ^ 1);
}
s.push_back(s.back());
s.push_back(s.back());
}
// for (int x : s) {
// cout << x;
// }
// cout << endl;
while (sz(s) < Declare()) {
s.push_back(s.back() ^ 1);
}
vector<int> t = {!parity};
while (sz(t) != sz(s)) {
t.push_back(t.back() ^ 1);
}
// for (int x : s) {
// cout << x;
// }
// cout << endl;
// for (int x : t) {
// cout << x << " ";
// }
// cout << endl;
if (parity) {
for (int &x : s) {
x ^= 1;
}
}
return {s, t};
}
vector<pair<int, int>> path;
#define TRY(x) do { if (x) { return true; }} while (false);
int n;
char d[2][N][N];
bool recover(const vector<int> &a, int i, int tlen, int cnt) {
{
int trem = n - tlen;
int srem = n - i + tlen;
int prv = sz(path) ? path.back().x : 1;
if (!cnt && d[prv ^ (srem & 1)][trem][srem]) {
return true;
}
}
if (i > sz(a) || tlen > n) {
return false;
}
if (a[i] != (tlen & 1)) {
TRY(recover(a, i + 1, tlen + 1, cnt));
}
if (cnt) {
if (path.back().x != a[i]) {
return false;
}
TRY(recover(a, i + 1, tlen, cnt - 1));
} else {
int prv = 1;
if (sz(path)) {
prv = path.back().x;
}
path.push_back({a[i], a[i] != prv});
TRY(recover(a, i + 1, tlen, a[i] == prv ? 1 : 2));
path.pop_back();
}
return false;
}
ll Bruno(vector<int> a) {
int parity = !a[0];
if (parity) {
for (int &x : a) {
x ^= 1;
}
}
Declare();
n = sz(a) / 2;
path.clear();
fill_n(d[0][0], 2 * N * N, 0);
d[0][0][0] = d[1][0][0] = 1;
int o1 = n & 1;
for (int o2 = 0; o2 < 2; ++o2) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
if (i && ((i & 1) ^ o1) != a[sz(a) - i - j]) {
d[o2][i][j] = d[o2][i - 1][j];
}
if (j && ((j & 1) ^ o2) != a[sz(a) - i - j]) {
d[o2][i][j] |= d[o2][i][j - 1];
}
}
}
}
// for (int x : a) {
// cout << x;
// }
// cout << endl;
// cout << d[1][145][144] << endl;
if (!recover(a, 1, 0, 0)) {
path.push_back({1, -1});
assert(recover(a, 0, 0, 1));
path.erase(path.begin());
}
// for (auto u : path) {
// cout << u.y << " ";
// }
// cout << endl;
// for (auto [_, x] : path) {
// cout << x << " ";
// }
// cout << endl;
int rlen = 1;
for (auto u : path) {
rlen += u.y + 2;
}
ll ans = 0;
for (int i = 0; i < rlen; ++i) {
ans += dp[i];
}
for (int i = 0; rlen > 1; ++i) {
if (path[i].y) {
ans += dp[rlen - 2];
rlen -= 3;
} else {
rlen -= 2;
}
}
return ans * 2 + parity;
}
//bs:sanitizers,flags:grader.cpp
#include "Anna.h"
#include "Bruno.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
const int LEN = 145, N = LEN + 1;
bool inited = false;
ll dp[N];
int Declare() {
if (inited) {
return LEN;
}
inited = true;
dp[1] = 1;
for (int i = 3; i < N; ++i) {
dp[i] = dp[i - 2] + dp[i - 3];
}
return LEN;
}
pair<vector<int>, vector<int>> Anna(ll n) {
bool parity = n & 1;
n /= 2;
int len = 0;
while (n >= dp[len]) {
n -= dp[len];
++len;
}
vector<int> u;
while (len > 1) {
if (n >= dp[len - 2]) {
u.push_back(1);
n -= dp[len - 2];
len -= 3;
} else {
u.push_back(0);
len -= 2;
}
}
// for (int x : u) {
// cout << x << " ";
// }
// cout << endl;
vector<int> s = {1};
for (int i : u) {
if (i) {
s.push_back(s.back() ^ 1);
}
s.push_back(s.back());
s.push_back(s.back());
}
// for (int x : s) {
// cout << x;
// }
// cout << endl;
while (sz(s) < Declare()) {
s.push_back(s.back() ^ 1);
}
vector<int> t = {!parity};
while (sz(t) != sz(s)) {
t.push_back(t.back() ^ 1);
}
// for (int x : s) {
// cout << x;
// }
// cout << endl;
// for (int x : t) {
// cout << x << " ";
// }
// cout << endl;
if (parity) {
for (int &x : s) {
x ^= 1;
}
}
return {s, t};
}
vector<pair<int, int>> path;
#define TRY(x) do { if (x) { return true; }} while (false);
int n;
char d[2][N][N];
bool recover(const vector<int> &a, int i, int tlen, int cnt) {
{
int trem = n - tlen;
int srem = n - i + tlen;
int prv = sz(path) ? path.back().x : 1;
if (!cnt && d[prv ^ (srem & 1)][trem][srem]) {
return true;
}
}
if (i > sz(a) || tlen > n) {
return false;
}
if (a[i] != (tlen & 1)) {
TRY(recover(a, i + 1, tlen + 1, cnt));
}
if (cnt) {
if (path.back().x != a[i]) {
return false;
}
TRY(recover(a, i + 1, tlen, cnt - 1));
} else {
int prv = 1;
if (sz(path)) {
prv = path.back().x;
}
path.push_back({a[i], a[i] != prv});
TRY(recover(a, i + 1, tlen, a[i] == prv ? 1 : 2));
path.pop_back();
}
return false;
}
ll Bruno(vector<int> a) {
int parity = !a[0];
if (parity) {
for (int &x : a) {
x ^= 1;
}
}
Declare();
n = sz(a) / 2;
path.clear();
fill_n(d[0][0], 2 * N * N, 0);
d[0][0][0] = d[1][0][0] = 1;
int o1 = n & 1;
for (int o2 = 0; o2 < 2; ++o2) {
for (int i = 0; i <= n; ++i) {
for (int j = 0; j <= n; ++j) {
if (i && ((i & 1) ^ o1) != a[sz(a) - i - j]) {
d[o2][i][j] = d[o2][i - 1][j];
}
if (j && ((j & 1) ^ o2) != a[sz(a) - i - j]) {
d[o2][i][j] |= d[o2][i][j - 1];
}
}
}
}
// for (int x : a) {
// cout << x;
// }
// cout << endl;
// cout << d[1][145][144] << endl;
if (!recover(a, 1, 0, 0)) {
path.push_back({1, -1});
assert(recover(a, 0, 0, 1));
path.erase(path.begin());
}
// for (auto u : path) {
// cout << u.y << " ";
// }
// cout << endl;
// for (auto [_, x] : path) {
// cout << x << " ";
// }
// cout << endl;
int rlen = 1;
for (auto u : path) {
rlen += u.y + 2;
}
ll ans = 0;
for (int i = 0; i < rlen; ++i) {
ans += dp[i];
}
for (int i = 0; rlen > 1; ++i) {
if (path[i].y) {
ans += dp[rlen - 2];
rlen -= 3;
} else {
rlen -= 2;
}
}
return ans * 2 + parity;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
179 ms |
2972 KB |
Output is correct |
3 |
Correct |
181 ms |
3088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
179 ms |
2972 KB |
Output is correct |
3 |
Correct |
181 ms |
3088 KB |
Output is correct |
4 |
Correct |
213 ms |
2948 KB |
Output is correct |
5 |
Correct |
193 ms |
3020 KB |
Output is correct |
6 |
Correct |
191 ms |
2964 KB |
Output is correct |
7 |
Correct |
186 ms |
2980 KB |
Output is correct |
8 |
Correct |
193 ms |
2948 KB |
Output is correct |
9 |
Correct |
198 ms |
2968 KB |
Output is correct |
10 |
Correct |
183 ms |
2964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
179 ms |
2972 KB |
Output is correct |
3 |
Correct |
181 ms |
3088 KB |
Output is correct |
4 |
Correct |
213 ms |
2948 KB |
Output is correct |
5 |
Correct |
193 ms |
3020 KB |
Output is correct |
6 |
Correct |
191 ms |
2964 KB |
Output is correct |
7 |
Correct |
186 ms |
2980 KB |
Output is correct |
8 |
Correct |
193 ms |
2948 KB |
Output is correct |
9 |
Correct |
198 ms |
2968 KB |
Output is correct |
10 |
Correct |
183 ms |
2964 KB |
Output is correct |
11 |
Correct |
188 ms |
3064 KB |
Output is correct |
12 |
Correct |
189 ms |
3000 KB |
Output is correct |
13 |
Correct |
193 ms |
2932 KB |
Output is correct |
14 |
Correct |
202 ms |
3000 KB |
Output is correct |
15 |
Correct |
193 ms |
3064 KB |
Output is correct |
16 |
Correct |
187 ms |
3068 KB |
Output is correct |
17 |
Correct |
174 ms |
3060 KB |
Output is correct |
18 |
Correct |
194 ms |
3000 KB |
Output is correct |
19 |
Correct |
192 ms |
2972 KB |
Output is correct |
20 |
Correct |
203 ms |
2984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
179 ms |
2972 KB |
Output is correct |
3 |
Correct |
181 ms |
3088 KB |
Output is correct |
4 |
Correct |
213 ms |
2948 KB |
Output is correct |
5 |
Correct |
193 ms |
3020 KB |
Output is correct |
6 |
Correct |
191 ms |
2964 KB |
Output is correct |
7 |
Correct |
186 ms |
2980 KB |
Output is correct |
8 |
Correct |
193 ms |
2948 KB |
Output is correct |
9 |
Correct |
198 ms |
2968 KB |
Output is correct |
10 |
Correct |
183 ms |
2964 KB |
Output is correct |
11 |
Correct |
188 ms |
3064 KB |
Output is correct |
12 |
Correct |
189 ms |
3000 KB |
Output is correct |
13 |
Correct |
193 ms |
2932 KB |
Output is correct |
14 |
Correct |
202 ms |
3000 KB |
Output is correct |
15 |
Correct |
193 ms |
3064 KB |
Output is correct |
16 |
Correct |
187 ms |
3068 KB |
Output is correct |
17 |
Correct |
174 ms |
3060 KB |
Output is correct |
18 |
Correct |
194 ms |
3000 KB |
Output is correct |
19 |
Correct |
192 ms |
2972 KB |
Output is correct |
20 |
Correct |
203 ms |
2984 KB |
Output is correct |
21 |
Correct |
192 ms |
3028 KB |
Output is correct |
22 |
Correct |
193 ms |
2976 KB |
Output is correct |
23 |
Correct |
191 ms |
2936 KB |
Output is correct |
24 |
Correct |
189 ms |
2952 KB |
Output is correct |
25 |
Correct |
190 ms |
2972 KB |
Output is correct |
26 |
Correct |
191 ms |
3052 KB |
Output is correct |
27 |
Correct |
185 ms |
3000 KB |
Output is correct |
28 |
Correct |
199 ms |
2940 KB |
Output is correct |
29 |
Correct |
190 ms |
3068 KB |
Output is correct |
30 |
Correct |
188 ms |
3012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
640 KB |
Output is correct |
2 |
Correct |
179 ms |
2972 KB |
Output is correct |
3 |
Correct |
181 ms |
3088 KB |
Output is correct |
4 |
Correct |
213 ms |
2948 KB |
Output is correct |
5 |
Correct |
193 ms |
3020 KB |
Output is correct |
6 |
Correct |
191 ms |
2964 KB |
Output is correct |
7 |
Correct |
186 ms |
2980 KB |
Output is correct |
8 |
Correct |
193 ms |
2948 KB |
Output is correct |
9 |
Correct |
198 ms |
2968 KB |
Output is correct |
10 |
Correct |
183 ms |
2964 KB |
Output is correct |
11 |
Correct |
188 ms |
3064 KB |
Output is correct |
12 |
Correct |
189 ms |
3000 KB |
Output is correct |
13 |
Correct |
193 ms |
2932 KB |
Output is correct |
14 |
Correct |
202 ms |
3000 KB |
Output is correct |
15 |
Correct |
193 ms |
3064 KB |
Output is correct |
16 |
Correct |
187 ms |
3068 KB |
Output is correct |
17 |
Correct |
174 ms |
3060 KB |
Output is correct |
18 |
Correct |
194 ms |
3000 KB |
Output is correct |
19 |
Correct |
192 ms |
2972 KB |
Output is correct |
20 |
Correct |
203 ms |
2984 KB |
Output is correct |
21 |
Correct |
192 ms |
3028 KB |
Output is correct |
22 |
Correct |
193 ms |
2976 KB |
Output is correct |
23 |
Correct |
191 ms |
2936 KB |
Output is correct |
24 |
Correct |
189 ms |
2952 KB |
Output is correct |
25 |
Correct |
190 ms |
2972 KB |
Output is correct |
26 |
Correct |
191 ms |
3052 KB |
Output is correct |
27 |
Correct |
185 ms |
3000 KB |
Output is correct |
28 |
Correct |
199 ms |
2940 KB |
Output is correct |
29 |
Correct |
190 ms |
3068 KB |
Output is correct |
30 |
Correct |
188 ms |
3012 KB |
Output is correct |
31 |
Correct |
191 ms |
2968 KB |
Output is correct |
32 |
Correct |
212 ms |
3108 KB |
Output is correct |
33 |
Correct |
209 ms |
3016 KB |
Output is correct |
34 |
Correct |
201 ms |
3000 KB |
Output is correct |
35 |
Correct |
204 ms |
2980 KB |
Output is correct |
36 |
Correct |
229 ms |
2948 KB |
Output is correct |
37 |
Correct |
191 ms |
3016 KB |
Output is correct |
38 |
Correct |
205 ms |
3076 KB |
Output is correct |
39 |
Correct |
205 ms |
3132 KB |
Output is correct |
40 |
Correct |
200 ms |
3008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
211 ms |
3060 KB |
Output is partially correct |
2 |
Partially correct |
219 ms |
3072 KB |
Output is partially correct |
3 |
Partially correct |
220 ms |
2956 KB |
Output is partially correct |
4 |
Partially correct |
231 ms |
3064 KB |
Output is partially correct |
5 |
Partially correct |
239 ms |
3136 KB |
Output is partially correct |
6 |
Partially correct |
219 ms |
3016 KB |
Output is partially correct |
7 |
Partially correct |
237 ms |
3096 KB |
Output is partially correct |
8 |
Partially correct |
230 ms |
3008 KB |
Output is partially correct |
9 |
Partially correct |
246 ms |
2952 KB |
Output is partially correct |
10 |
Partially correct |
221 ms |
3132 KB |
Output is partially correct |
11 |
Partially correct |
206 ms |
2984 KB |
Output is partially correct |
12 |
Partially correct |
227 ms |
2952 KB |
Output is partially correct |
13 |
Partially correct |
219 ms |
3044 KB |
Output is partially correct |
14 |
Partially correct |
196 ms |
2972 KB |
Output is partially correct |
15 |
Partially correct |
208 ms |
3076 KB |
Output is partially correct |
16 |
Partially correct |
198 ms |
2960 KB |
Output is partially correct |
17 |
Partially correct |
204 ms |
3096 KB |
Output is partially correct |
18 |
Partially correct |
202 ms |
3084 KB |
Output is partially correct |
19 |
Partially correct |
198 ms |
3004 KB |
Output is partially correct |
20 |
Partially correct |
201 ms |
2968 KB |
Output is partially correct |