#include <bits/stdc++.h>
#include "Anna.h"
namespace {
using ll = long long;
template <class T> using Vec = std::vector<T>;
ll encode(const std::array<int, 63>& arr) {
std::array<std::array<ll, 2>, 2> dp{};
dp[0][0] = 1;
for (const auto x : arr) {
std::array<std::array<ll, 2>, 2> next{};
for (const int i : {0, 1}) {
for (const int j : {0, 1}) {
for (const int k : {0, 1}) {
if ((!i and x < k) or j + k == 2) {
continue;
}
next[i || (k < x)][k] += dp[i][j];
}
}
}
dp = std::move(next);
}
return dp[1][0] + dp[1][1];
}
}
void Anna(int N, Vec<char> S) {
int idx = 0;
while (idx < N and S[idx] != 'X') {
idx += 1;
}
for (int i = 0; i < 17; ++i) {
Send(idx >> i & 1);
}
Vec<int> seq(N);
for (int i = idx + 1; i < N; ++i) {
if (S[i] == 'Z' and (i + 1 == N or S[i + 1] != 'Z')) {
seq[i] = 1;
}
}
for (int l = 0; l < N; l += 63) {
std::array<int, 63> arr;
for (int i = 0; i < 63; ++i) {
arr[i] = (l + i >= N ? 0 : seq[l + i]);
}
const ll x = encode(arr);
for (int i = 0; i < 44; ++i) {
Send(x >> i & 1);
}
}
}
#include <bits/stdc++.h>
#include "Bruno.h"
namespace {
using ll = long long;
template <class T> using Vec = std::vector<T>;
constexpr std::array<ll, 63> FIB = [] {
std::array<ll, 63> ret{};
ret[0] = 1;
ret[1] = 2;
for (int i = 2; i < 63; ++i) {
ret[i] = ret[i - 1] + ret[i - 2];
}
return ret;
}();
std::array<int, 63> decode(ll x) {
std::array<int, 63> ret{};
int idx = 0;
while (idx < 63) {
if (x >= FIB[62 - idx]) {
x -= FIB[62 - idx];
ret[idx] = 1;
idx += 2;
} else {
idx += 1;
}
}
return ret;
}
} // namespace
void Bruno(int N, int L, Vec<int> A) {
int Xpos = 0;
for (int i = 0; i < 17; ++i) {
Xpos |= A[i] << i;
}
int idx = 0;
Vec<int> vec;
for (int i = 17; i < L; i += 44) {
ll x = 0;
for (int k = 0; k < 44; ++k) {
x |= (ll) A[i + k] << k;
}
for (const auto y : decode(x)) {
if (y) {
vec.push_back(idx);
}
idx += 1;
}
}
Vec<int> removed(N);
for (const auto i : vec) {
for (int j = i - 1; j > Xpos; --j) {
Remove(j);
removed[j] = true;
}
Remove(i);
removed[i] = true;
Xpos = i;
}
for (int i = 0; i < N; ++i) {
if (!removed[i]) {
Remove(i);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
476 KB |
Output is correct |
4 |
Correct |
1 ms |
488 KB |
Output is correct |
5 |
Correct |
2 ms |
480 KB |
Output is correct |
6 |
Correct |
2 ms |
484 KB |
Output is correct |
7 |
Correct |
2 ms |
484 KB |
Output is correct |
8 |
Correct |
2 ms |
484 KB |
Output is correct |
9 |
Correct |
2 ms |
484 KB |
Output is correct |
10 |
Correct |
2 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
7988 KB |
Output is correct |
2 |
Correct |
74 ms |
8264 KB |
Output is correct |
3 |
Correct |
65 ms |
8432 KB |
Output is correct |
4 |
Correct |
79 ms |
8400 KB |
Output is correct |
5 |
Correct |
65 ms |
8324 KB |
Output is correct |
6 |
Correct |
62 ms |
8420 KB |
Output is correct |
7 |
Correct |
69 ms |
8332 KB |
Output is correct |
8 |
Correct |
68 ms |
8468 KB |
Output is correct |
9 |
Correct |
68 ms |
8320 KB |
Output is correct |
10 |
Correct |
73 ms |
8420 KB |
Output is correct |
11 |
Correct |
75 ms |
8652 KB |
Output is correct |
12 |
Correct |
72 ms |
8472 KB |
Output is correct |
13 |
Correct |
73 ms |
8380 KB |
Output is correct |
14 |
Correct |
75 ms |
8560 KB |
Output is correct |
15 |
Correct |
67 ms |
8368 KB |
Output is correct |
16 |
Correct |
71 ms |
8324 KB |
Output is correct |
17 |
Correct |
77 ms |
8304 KB |
Output is correct |
18 |
Correct |
69 ms |
8172 KB |
Output is correct |
19 |
Correct |
80 ms |
8288 KB |
Output is correct |
20 |
Correct |
68 ms |
8416 KB |
Output is correct |
21 |
Correct |
62 ms |
8424 KB |
Output is correct |
22 |
Correct |
74 ms |
8296 KB |
Output is correct |
23 |
Correct |
66 ms |
8288 KB |
Output is correct |
24 |
Correct |
71 ms |
8416 KB |
Output is correct |
25 |
Correct |
73 ms |
8220 KB |
Output is correct |
26 |
Correct |
80 ms |
8320 KB |
Output is correct |
27 |
Correct |
75 ms |
8152 KB |
Output is correct |
28 |
Correct |
79 ms |
8360 KB |
Output is correct |
29 |
Correct |
81 ms |
8264 KB |
Output is correct |
30 |
Correct |
68 ms |
8384 KB |
Output is correct |
31 |
Correct |
81 ms |
8308 KB |
Output is correct |
32 |
Correct |
63 ms |
8380 KB |
Output is correct |
33 |
Correct |
68 ms |
8416 KB |
Output is correct |