//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;
bool inited = false;
ll dp[LEN + 1];
int Declare() {
if (inited) {
return LEN;
}
inited = true;
dp[1] = 1;
for (int i = 3; i <= LEN; ++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());
}
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 &u : s) {
u ^= 1;
}
}
return {s, t};
}
vector<pair<int, int>> path;
#define TRY(x) do { if (x) { return true; }} while (false);
int n;
bool recover(const vector<int> &a, int i, int tlen, int cnt) {
if (i == sz(a)) {
return tlen == n && !cnt;
}
if (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();
// for (int x : a) {
// cout << x << " ";
// }
// cout << endl;
if (!recover(a, 1, 0, 0)) {
path.push_back({1, -1});
assert(recover(a, 0, 0, 1));
path.erase(path.begin());
}
// for (auto [_, x] : path) {
// cout << x << " ";
// }
// cout << endl;
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += dp[i];
}
for (int i = 0; n > 1; ++i) {
if (path[i].y) {
ans += dp[n - 2];
n -= 3;
} else {
n -= 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;
bool inited = false;
ll dp[LEN + 1];
int Declare() {
if (inited) {
return LEN;
}
inited = true;
dp[1] = 1;
for (int i = 3; i <= LEN; ++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());
}
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 &u : s) {
u ^= 1;
}
}
return {s, t};
}
vector<pair<int, int>> path;
#define TRY(x) do { if (x) { return true; }} while (false);
int n;
bool recover(const vector<int> &a, int i, int tlen, int cnt) {
if (i == sz(a)) {
return tlen == n && !cnt;
}
if (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();
// for (int x : a) {
// cout << x << " ";
// }
// cout << endl;
if (!recover(a, 1, 0, 0)) {
path.push_back({1, -1});
assert(recover(a, 0, 0, 1));
path.erase(path.begin());
}
// for (auto [_, x] : path) {
// cout << x << " ";
// }
// cout << endl;
ll ans = 0;
for (int i = 0; i < n; ++i) {
ans += dp[i];
}
for (int i = 0; n > 1; ++i) {
if (path[i].y) {
ans += dp[n - 2];
n -= 3;
} else {
n -= 2;
}
}
return ans * 2 + parity;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
952 KB |
Output is correct |
3 |
Correct |
17 ms |
928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
952 KB |
Output is correct |
3 |
Correct |
17 ms |
928 KB |
Output is correct |
4 |
Correct |
27 ms |
1248 KB |
Output is correct |
5 |
Correct |
27 ms |
1372 KB |
Output is correct |
6 |
Correct |
28 ms |
1340 KB |
Output is correct |
7 |
Correct |
30 ms |
1288 KB |
Output is correct |
8 |
Correct |
27 ms |
1296 KB |
Output is correct |
9 |
Correct |
27 ms |
1288 KB |
Output is correct |
10 |
Correct |
28 ms |
1356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
952 KB |
Output is correct |
3 |
Correct |
17 ms |
928 KB |
Output is correct |
4 |
Correct |
27 ms |
1248 KB |
Output is correct |
5 |
Correct |
27 ms |
1372 KB |
Output is correct |
6 |
Correct |
28 ms |
1340 KB |
Output is correct |
7 |
Correct |
30 ms |
1288 KB |
Output is correct |
8 |
Correct |
27 ms |
1296 KB |
Output is correct |
9 |
Correct |
27 ms |
1288 KB |
Output is correct |
10 |
Correct |
28 ms |
1356 KB |
Output is correct |
11 |
Correct |
30 ms |
1456 KB |
Output is correct |
12 |
Correct |
28 ms |
1456 KB |
Output is correct |
13 |
Correct |
28 ms |
1416 KB |
Output is correct |
14 |
Correct |
33 ms |
1480 KB |
Output is correct |
15 |
Correct |
35 ms |
1412 KB |
Output is correct |
16 |
Correct |
31 ms |
1464 KB |
Output is correct |
17 |
Correct |
30 ms |
1480 KB |
Output is correct |
18 |
Correct |
27 ms |
1320 KB |
Output is correct |
19 |
Correct |
26 ms |
1432 KB |
Output is correct |
20 |
Correct |
25 ms |
1292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
952 KB |
Output is correct |
3 |
Correct |
17 ms |
928 KB |
Output is correct |
4 |
Correct |
27 ms |
1248 KB |
Output is correct |
5 |
Correct |
27 ms |
1372 KB |
Output is correct |
6 |
Correct |
28 ms |
1340 KB |
Output is correct |
7 |
Correct |
30 ms |
1288 KB |
Output is correct |
8 |
Correct |
27 ms |
1296 KB |
Output is correct |
9 |
Correct |
27 ms |
1288 KB |
Output is correct |
10 |
Correct |
28 ms |
1356 KB |
Output is correct |
11 |
Correct |
30 ms |
1456 KB |
Output is correct |
12 |
Correct |
28 ms |
1456 KB |
Output is correct |
13 |
Correct |
28 ms |
1416 KB |
Output is correct |
14 |
Correct |
33 ms |
1480 KB |
Output is correct |
15 |
Correct |
35 ms |
1412 KB |
Output is correct |
16 |
Correct |
31 ms |
1464 KB |
Output is correct |
17 |
Correct |
30 ms |
1480 KB |
Output is correct |
18 |
Correct |
27 ms |
1320 KB |
Output is correct |
19 |
Correct |
26 ms |
1432 KB |
Output is correct |
20 |
Correct |
25 ms |
1292 KB |
Output is correct |
21 |
Correct |
34 ms |
1608 KB |
Output is correct |
22 |
Correct |
32 ms |
1552 KB |
Output is correct |
23 |
Correct |
32 ms |
1624 KB |
Output is correct |
24 |
Correct |
32 ms |
1500 KB |
Output is correct |
25 |
Correct |
33 ms |
1620 KB |
Output is correct |
26 |
Correct |
33 ms |
1604 KB |
Output is correct |
27 |
Correct |
31 ms |
1628 KB |
Output is correct |
28 |
Correct |
27 ms |
1332 KB |
Output is correct |
29 |
Correct |
27 ms |
1524 KB |
Output is correct |
30 |
Correct |
28 ms |
1496 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
512 KB |
Output is correct |
2 |
Correct |
16 ms |
952 KB |
Output is correct |
3 |
Correct |
17 ms |
928 KB |
Output is correct |
4 |
Correct |
27 ms |
1248 KB |
Output is correct |
5 |
Correct |
27 ms |
1372 KB |
Output is correct |
6 |
Correct |
28 ms |
1340 KB |
Output is correct |
7 |
Correct |
30 ms |
1288 KB |
Output is correct |
8 |
Correct |
27 ms |
1296 KB |
Output is correct |
9 |
Correct |
27 ms |
1288 KB |
Output is correct |
10 |
Correct |
28 ms |
1356 KB |
Output is correct |
11 |
Correct |
30 ms |
1456 KB |
Output is correct |
12 |
Correct |
28 ms |
1456 KB |
Output is correct |
13 |
Correct |
28 ms |
1416 KB |
Output is correct |
14 |
Correct |
33 ms |
1480 KB |
Output is correct |
15 |
Correct |
35 ms |
1412 KB |
Output is correct |
16 |
Correct |
31 ms |
1464 KB |
Output is correct |
17 |
Correct |
30 ms |
1480 KB |
Output is correct |
18 |
Correct |
27 ms |
1320 KB |
Output is correct |
19 |
Correct |
26 ms |
1432 KB |
Output is correct |
20 |
Correct |
25 ms |
1292 KB |
Output is correct |
21 |
Correct |
34 ms |
1608 KB |
Output is correct |
22 |
Correct |
32 ms |
1552 KB |
Output is correct |
23 |
Correct |
32 ms |
1624 KB |
Output is correct |
24 |
Correct |
32 ms |
1500 KB |
Output is correct |
25 |
Correct |
33 ms |
1620 KB |
Output is correct |
26 |
Correct |
33 ms |
1604 KB |
Output is correct |
27 |
Correct |
31 ms |
1628 KB |
Output is correct |
28 |
Correct |
27 ms |
1332 KB |
Output is correct |
29 |
Correct |
27 ms |
1524 KB |
Output is correct |
30 |
Correct |
28 ms |
1496 KB |
Output is correct |
31 |
Correct |
43 ms |
2084 KB |
Output is correct |
32 |
Correct |
43 ms |
2108 KB |
Output is correct |
33 |
Correct |
41 ms |
1928 KB |
Output is correct |
34 |
Correct |
46 ms |
1996 KB |
Output is correct |
35 |
Correct |
43 ms |
2056 KB |
Output is correct |
36 |
Correct |
46 ms |
1944 KB |
Output is correct |
37 |
Correct |
40 ms |
2012 KB |
Output is correct |
38 |
Correct |
40 ms |
1916 KB |
Output is correct |
39 |
Correct |
38 ms |
1864 KB |
Output is correct |
40 |
Correct |
39 ms |
1972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
68 ms |
2876 KB |
Output is partially correct |
2 |
Partially correct |
72 ms |
2920 KB |
Output is partially correct |
3 |
Partially correct |
67 ms |
2944 KB |
Output is partially correct |
4 |
Partially correct |
68 ms |
2832 KB |
Output is partially correct |
5 |
Partially correct |
65 ms |
2920 KB |
Output is partially correct |
6 |
Partially correct |
65 ms |
2996 KB |
Output is partially correct |
7 |
Partially correct |
64 ms |
2864 KB |
Output is partially correct |
8 |
Partially correct |
65 ms |
2840 KB |
Output is partially correct |
9 |
Partially correct |
67 ms |
2948 KB |
Output is partially correct |
10 |
Partially correct |
66 ms |
2928 KB |
Output is partially correct |
11 |
Partially correct |
66 ms |
2960 KB |
Output is partially correct |
12 |
Partially correct |
64 ms |
2924 KB |
Output is partially correct |
13 |
Partially correct |
64 ms |
2916 KB |
Output is partially correct |
14 |
Partially correct |
61 ms |
2868 KB |
Output is partially correct |
15 |
Partially correct |
61 ms |
2704 KB |
Output is partially correct |
16 |
Partially correct |
60 ms |
2820 KB |
Output is partially correct |
17 |
Partially correct |
57 ms |
2852 KB |
Output is partially correct |
18 |
Partially correct |
59 ms |
2796 KB |
Output is partially correct |
19 |
Partially correct |
68 ms |
2768 KB |
Output is partially correct |
20 |
Partially correct |
67 ms |
2640 KB |
Output is partially correct |