#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[63] = {1, 2};
void precomp() { for (int i = 2; i < 63; ++i) dp[i] = dp[i - 1] + dp[i - 2]; }
void Anna(int N, vector<char> S) {
precomp();
vector<bool> bits;
bool x = false;
char last = 0;
for (char c: S) {
if (x) {
if (c == 'Z') {
if (last == 'Z') bits.back() = 0;
bits.emplace_back(1);
} else bits.emplace_back(0);
}
else if (c == 'X') x = true, bits.emplace_back(1), bits.emplace_back(0);
else bits.emplace_back(0);
last = c;
}
while (bits.size() % 63) bits.emplace_back(0);
function<ll(ll, int)> encode = [&] (ll x, int i) {
if (i < 0) return 0ll;
if ((x >> i) & 1) return dp[i] + encode(x, i - 2);
else return encode(x, i - 1);
};
for (int i = 0; i * 63 < bits.size(); ++i) {
ll hash = 0;
for (int j = 0; j < 63; ++j) hash |= (ll) bits[i * 63 + j] << j;
hash = encode(hash, 62);
for (int j = 0; j < 44; ++j) Send((hash >> j) & 1);
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll dp[63] = {1, 2};
void precomp() { for (int i = 2; i < 63; ++i) dp[i] = dp[i - 1] + dp[i - 2]; }
void Bruno(int N, int L, vector<int> A) {
precomp();
vector<bool> bits;
function<ll(ll, int)> decode = [&] (ll x, int i) {
if (i < 0) return 0ll;
if (x < dp[i]) return decode(x, i - 1);
else return (1ll << i) | decode(x - dp[i], i - 2);
};
for (int i = 0; i * 44 < L; ++i) {
ll hash = 0;
for (int j = 0; j < 44; ++j) hash |= (ll) A[i * 44 + j] << j;
hash = decode(hash, 62);
for (int j = 0; j < 63; ++j) bits.emplace_back((hash >> j) & 1);
}
int x = N;
vector<int> batch;
for (int i = 0; i <= N; ++i) {
if (i == N and x == N) break;
if (x < N and bits[i]) {
for (; batch.size() > 1 and batch.back() > x; batch.pop_back()) Remove(batch.back());
Remove(i - 1);
continue;
}
if (x < N) {
if (i - 1 != x) batch.push_back(i - 1);
} else {
batch.push_back(i);
if (bits[i]) x = i;
}
}
for (int i: batch) Remove(i);
}
Compilation message
Anna.cpp: In function 'void Anna(int, std::vector<char>)':
Anna.cpp:33:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bool>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i = 0; i * 63 < bits.size(); ++i) {
| ~~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
780 KB |
Output is correct |
2 |
Correct |
0 ms |
792 KB |
Output is correct |
3 |
Correct |
0 ms |
792 KB |
Output is correct |
4 |
Correct |
0 ms |
792 KB |
Output is correct |
5 |
Correct |
0 ms |
780 KB |
Output is correct |
6 |
Correct |
0 ms |
772 KB |
Output is correct |
7 |
Correct |
0 ms |
776 KB |
Output is correct |
8 |
Correct |
0 ms |
780 KB |
Output is correct |
9 |
Correct |
0 ms |
788 KB |
Output is correct |
10 |
Correct |
0 ms |
780 KB |
Output is correct |
11 |
Correct |
0 ms |
792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
7808 KB |
Output is correct |
2 |
Correct |
28 ms |
7636 KB |
Output is correct |
3 |
Correct |
31 ms |
7808 KB |
Output is correct |
4 |
Correct |
28 ms |
7692 KB |
Output is correct |
5 |
Correct |
27 ms |
7756 KB |
Output is correct |
6 |
Correct |
27 ms |
7652 KB |
Output is correct |
7 |
Correct |
28 ms |
7644 KB |
Output is correct |
8 |
Correct |
27 ms |
7820 KB |
Output is correct |
9 |
Correct |
31 ms |
7720 KB |
Output is correct |
10 |
Correct |
27 ms |
7768 KB |
Output is correct |
11 |
Correct |
32 ms |
7812 KB |
Output is correct |
12 |
Correct |
32 ms |
7804 KB |
Output is correct |
13 |
Correct |
32 ms |
7828 KB |
Output is correct |
14 |
Correct |
33 ms |
7664 KB |
Output is correct |
15 |
Correct |
30 ms |
7780 KB |
Output is correct |
16 |
Correct |
26 ms |
7776 KB |
Output is correct |
17 |
Correct |
32 ms |
7864 KB |
Output is correct |
18 |
Correct |
32 ms |
7832 KB |
Output is correct |
19 |
Correct |
34 ms |
7832 KB |
Output is correct |
20 |
Correct |
27 ms |
7820 KB |
Output is correct |
21 |
Correct |
31 ms |
7804 KB |
Output is correct |
22 |
Correct |
33 ms |
7696 KB |
Output is correct |
23 |
Correct |
27 ms |
8104 KB |
Output is correct |
24 |
Correct |
27 ms |
7804 KB |
Output is correct |
25 |
Correct |
33 ms |
7744 KB |
Output is correct |
26 |
Correct |
34 ms |
7776 KB |
Output is correct |
27 |
Correct |
33 ms |
7952 KB |
Output is correct |
28 |
Correct |
33 ms |
7816 KB |
Output is correct |
29 |
Correct |
34 ms |
7824 KB |
Output is correct |
30 |
Correct |
32 ms |
7796 KB |
Output is correct |
31 |
Correct |
34 ms |
7844 KB |
Output is correct |
32 |
Correct |
27 ms |
7816 KB |
Output is correct |
33 |
Correct |
35 ms |
7748 KB |
Output is correct |