#include "Anna.h"
#include <bits/stdc++.h>
void Anna(int n, std::vector <char> a) {
const int kFibonacci = 63;
const int kLog = 50;
std::vector <long long> dp(kFibonacci);
dp[0] = 1;
dp[1] = 2;
for (int i = 2; i < kFibonacci; i += 1) {
dp[i] = dp[i - 1] + dp[i - 2];
}
std::vector <int> b(n);
bool found = 0;
for (int i = 0; i < n; i += 1) {
int bit = 0;
if (not found and a[i] == 'X') {
bit = 1;
found = true;
}
if (found and a[i] == 'Z' and (i + 1 == n or a[i + 1] != 'Z') and (b[i - 1] != 1)) {
bit = 1;
}
b[i] = bit;
}
auto SendEncode = [&] (std::vector <int> z) -> void {
long long x = 0;
for (int i = 0; i < kFibonacci; i += 1) {
x += z[i] ? dp[i] : 0;
}
assert((1LL << kLog) - 1 >= x);
for (int i = 0; i < kLog; i += 1) {
Send((x >> i) & 1);
}
};
while (b.size() % kFibonacci)
b.push_back(0);
for (int l = 0, r = kFibonacci; r <= (int) b.size(); l += kFibonacci, r += kFibonacci) {
SendEncode(std::vector <int> (b.begin() + l, b.begin() + r));
}
}
#include "Bruno.h"
#include <bits/stdc++.h>
void Bruno(int n, int, std::vector <int> a) {
const int kFibonacci = 63;
const int kLog = 50;
std::vector <long long> dp(kFibonacci);
dp[0] = 1;
dp[1] = 2;
for (int i = 2; i < kFibonacci; i += 1) {
dp[i] = dp[i - 1] + dp[i - 2];
}
std::vector <int> posOne;
for (int l = 0, r = kLog; r <= (int) a.size(); l += kLog, r += kLog) {
long long x = 0;
for (int i = l; i < r; i += 1)
x += (1LL * a[i]) << (i - l);
int p = l / kLog;
for (int i = kFibonacci - 1; i >= 0; i -= 1) {
if (x >= dp[i]) {
x -= dp[i];
posOne.push_back(p * kFibonacci + i);
}
}
}
std::sort(posOne.begin(), posOne.end());
if (posOne.size() < 2) {
for (int i = 0; i < n; i += 1)
Remove(i);
return;
}
int x = posOne[0];
for (int i = 0; i < x; i += 1) {
Remove(i);
}
for (int i = 0; i + 1 < (int) posOne.size(); i += 1) {
for (int j = posOne[i + 1] - 1; j > posOne[i]; j -= 1)
Remove(j);
Remove(posOne[i + 1]);
}
for (int j = posOne.back() + 1; j < n; j += 1) {
Remove(j);
}
Remove(x);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
796 KB |
Output is correct |
2 |
Correct |
0 ms |
772 KB |
Output is correct |
3 |
Correct |
0 ms |
1288 KB |
Output is correct |
4 |
Correct |
0 ms |
788 KB |
Output is correct |
5 |
Correct |
0 ms |
788 KB |
Output is correct |
6 |
Correct |
0 ms |
780 KB |
Output is correct |
7 |
Correct |
0 ms |
780 KB |
Output is correct |
8 |
Correct |
0 ms |
780 KB |
Output is correct |
9 |
Correct |
0 ms |
792 KB |
Output is correct |
10 |
Correct |
1 ms |
788 KB |
Output is correct |
11 |
Correct |
1 ms |
788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
38 ms |
8140 KB |
Partially correct |
2 |
Partially correct |
39 ms |
8224 KB |
Partially correct |
3 |
Incorrect |
37 ms |
8128 KB |
Wrong Answer [6] |
4 |
Halted |
0 ms |
0 KB |
- |