#include <bits/stdc++.h>
#include "Anna.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;
}();
ll encode(const std::array<int, 63>& arr) {
ll x = 0;
for (int i = 0; i < 63; ++i) {
if (arr[i]) {
x += FIB[62 - i];
}
}
return x;
}
}
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);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
504 KB |
Output is correct |
2 |
Correct |
1 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
484 KB |
Output is correct |
6 |
Correct |
1 ms |
496 KB |
Output is correct |
7 |
Correct |
1 ms |
484 KB |
Output is correct |
8 |
Correct |
1 ms |
484 KB |
Output is correct |
9 |
Correct |
1 ms |
480 KB |
Output is correct |
10 |
Correct |
1 ms |
484 KB |
Output is correct |
11 |
Correct |
1 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
61 ms |
8012 KB |
Output is correct |
2 |
Correct |
77 ms |
7916 KB |
Output is correct |
3 |
Correct |
60 ms |
7976 KB |
Output is correct |
4 |
Correct |
68 ms |
8068 KB |
Output is correct |
5 |
Correct |
59 ms |
8024 KB |
Output is correct |
6 |
Correct |
73 ms |
7972 KB |
Output is correct |
7 |
Correct |
66 ms |
8100 KB |
Output is correct |
8 |
Correct |
62 ms |
8004 KB |
Output is correct |
9 |
Correct |
68 ms |
8008 KB |
Output is correct |
10 |
Correct |
62 ms |
7876 KB |
Output is correct |
11 |
Correct |
79 ms |
8036 KB |
Output is correct |
12 |
Correct |
67 ms |
8072 KB |
Output is correct |
13 |
Correct |
65 ms |
7848 KB |
Output is correct |
14 |
Correct |
71 ms |
8108 KB |
Output is correct |
15 |
Correct |
86 ms |
7900 KB |
Output is correct |
16 |
Correct |
64 ms |
8120 KB |
Output is correct |
17 |
Correct |
76 ms |
7820 KB |
Output is correct |
18 |
Correct |
76 ms |
7868 KB |
Output is correct |
19 |
Correct |
85 ms |
8156 KB |
Output is correct |
20 |
Correct |
83 ms |
8020 KB |
Output is correct |
21 |
Correct |
68 ms |
7992 KB |
Output is correct |
22 |
Correct |
76 ms |
7856 KB |
Output is correct |
23 |
Correct |
75 ms |
7964 KB |
Output is correct |
24 |
Correct |
78 ms |
8080 KB |
Output is correct |
25 |
Correct |
77 ms |
7928 KB |
Output is correct |
26 |
Correct |
77 ms |
7928 KB |
Output is correct |
27 |
Correct |
81 ms |
8020 KB |
Output is correct |
28 |
Correct |
77 ms |
7912 KB |
Output is correct |
29 |
Correct |
71 ms |
7832 KB |
Output is correct |
30 |
Correct |
84 ms |
7836 KB |
Output is correct |
31 |
Correct |
80 ms |
7960 KB |
Output is correct |
32 |
Correct |
73 ms |
7900 KB |
Output is correct |
33 |
Correct |
69 ms |
8024 KB |
Output is correct |