#include<bits/stdc++.h>
#include "Anna.h"
#include <vector>
using namespace std;
typedef long long llint;
const int MAXN = 90;
const int SIZ = 63;
llint fib[MAXN];
int get_bits (llint val) {
int res = 0;
llint pot = 1;
for (int i = 0; i < 50; i++) {
if (val & pot) res = i + 1;
pot *= 2;
}
return res;
}
void precompute () {
fib[0] = 0; fib[1] = 1;
for (int i = 2; i < MAXN; i++) {
fib[i] = fib[i - 1] + fib[i - 2];
}
}
void send_num (llint val, int br) {
llint pot = 1;
for (int i = 0; i < br; i++) {
if (val & pot) Send(1); else Send(0);
pot *= 2;
}
}
llint compress (vector <int> v) {
int n = 0;
for (auto x : v) n += x;
llint res = 1;
for (auto x : v) {
if (x == 1) {
n--;
} else {
res += fib[n];
n -= 2;
}
}
return res;
}
void Anna (int N, vector <char> S) {
precompute();
int lef = N, rig = N;
for (int i = 0; i < N; i++) {
if (S[i] == 'X') {
lef = i;
break;
}
}
for (int i = N-1; i >= 0; i--) {
if (S[i] == 'Z') {
rig = i;
break;
}
}
send_num(lef, 17);
send_num(rig, 17);
vector <int> r((SIZ + 1) / 2, 2);
int bits = get_bits(compress(r));
vector <int> v;
for (int i = 0; i < N; i++) {
if (i + 1 < N && S[i] == 'Y' && S[i + 1] == 'X') {
v.push_back(2);
i++;
} else {
v.push_back(1);
}
}
vector <int> tmp;
int sum = 0;
for (auto x : v) {
tmp.push_back(x);
sum += x;
if (sum >= SIZ) {
if (sum == SIZ) tmp.push_back(1);
send_num(compress(tmp), bits);
tmp.clear();
sum = 0;
}
}
if (!tmp.empty()) {
while (sum < SIZ + 1) {
tmp.push_back(1);
sum++;
}
send_num(compress(tmp), bits);
}
}
#include<bits/stdc++.h>
#include "Bruno.h"
#include <vector>
using namespace std;
typedef long long llint;
const int MAXN = 90;
const int SIZ = 63;
llint fib_bruno[MAXN];
int a_pos;
vector <int> a;
int get_bits_bruno (llint val) {
int res = 0;
llint pot = 1;
for (int i = 0; i < 50; i++) {
if (val & pot) res = i + 1;
pot *= 2;
}
return res;
}
void precompute_bruno () {
fib_bruno[0] = 0; fib_bruno[1] = 1;
for (int i = 2; i < MAXN; i++) {
fib_bruno[i] = fib_bruno[i - 1] + fib_bruno[i - 2];
}
}
llint get_num (int br) {
llint res = 0;
llint pot = 1;
for (int i = 0; i < br; i++) {
res += pot * a[a_pos];
a_pos++;
pot *= 2;
}
return res;
}
llint compress_bruno (vector <int> v) {
int n = 0;
for (auto x : v) n += x;
llint res = 1;
for (auto x : v) {
if (x == 1) {
n--;
} else {
res += fib_bruno[n];
n -= 2;
}
}
return res;
}
vector <int> decompress (llint val) {
vector <int> v;
int n = SIZ + 1;
while (n > 0) {
if (val > fib_bruno[n]) {
val -= fib_bruno[n];
v.push_back(2);
n -= 2;
} else {
v.push_back(1);
n--;
}
}
return v;
}
void ispis (vector <int> v) {
for (auto x : v) cout << x << " "; cout << endl;
}
void Bruno (int N, int L, vector <int> A) {
a = A;
precompute_bruno();
vector <int> r((SIZ + 1) / 2, 2);
int bits = get_bits_bruno(compress_bruno(r));
int lef = get_num(17);
int rig = get_num(17);
vector <int> v;
while (a_pos < L) {
llint val = get_num(bits);
vector <int> tmp = decompress(val);
if (tmp.back() == 1) tmp.pop_back();
for (auto x : tmp) {
if (x == 1) v.push_back(1);
if (x == 2) v.push_back(0), v.push_back(0);
}
}
v[lef] = 0; v[rig] = 0;
for (int i = 0; i < N; i++) {
if (v[i] == 1) Remove(i);
}
for (int i = N - 1; i >= 0; i--) {
if (i == lef || i == rig) continue;
if (v[i] == 0) Remove(i);
}
if (lef < N) Remove(lef);
if (rig < N) Remove(rig);
}
Compilation message
Bruno.cpp: In function 'void ispis(std::vector<int>)':
Bruno.cpp:76:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
76 | for (auto x : v) cout << x << " "; cout << endl;
| ^~~
Bruno.cpp:76:37: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
76 | for (auto x : v) cout << x << " "; cout << endl;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
484 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
484 KB |
Output is correct |
4 |
Correct |
2 ms |
484 KB |
Output is correct |
5 |
Correct |
2 ms |
484 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 |
480 KB |
Output is correct |
9 |
Correct |
2 ms |
484 KB |
Output is correct |
10 |
Correct |
2 ms |
484 KB |
Output is correct |
11 |
Correct |
2 ms |
484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
8296 KB |
Output is correct |
2 |
Correct |
76 ms |
8340 KB |
Output is correct |
3 |
Correct |
72 ms |
8320 KB |
Output is correct |
4 |
Correct |
68 ms |
8280 KB |
Output is correct |
5 |
Correct |
70 ms |
8280 KB |
Output is correct |
6 |
Correct |
70 ms |
8264 KB |
Output is correct |
7 |
Correct |
84 ms |
8184 KB |
Output is correct |
8 |
Correct |
68 ms |
8344 KB |
Output is correct |
9 |
Correct |
69 ms |
8340 KB |
Output is correct |
10 |
Correct |
84 ms |
8324 KB |
Output is correct |
11 |
Correct |
91 ms |
8312 KB |
Output is correct |
12 |
Correct |
85 ms |
8328 KB |
Output is correct |
13 |
Correct |
68 ms |
7852 KB |
Output is correct |
14 |
Correct |
70 ms |
8248 KB |
Output is correct |
15 |
Correct |
71 ms |
8248 KB |
Output is correct |
16 |
Correct |
61 ms |
8272 KB |
Output is correct |
17 |
Correct |
72 ms |
8396 KB |
Output is correct |
18 |
Correct |
69 ms |
8260 KB |
Output is correct |
19 |
Correct |
72 ms |
8364 KB |
Output is correct |
20 |
Correct |
72 ms |
8264 KB |
Output is correct |
21 |
Correct |
67 ms |
8228 KB |
Output is correct |
22 |
Correct |
69 ms |
8316 KB |
Output is correct |
23 |
Correct |
84 ms |
8148 KB |
Output is correct |
24 |
Correct |
91 ms |
8088 KB |
Output is correct |
25 |
Correct |
82 ms |
8336 KB |
Output is correct |
26 |
Correct |
83 ms |
8272 KB |
Output is correct |
27 |
Correct |
68 ms |
8256 KB |
Output is correct |
28 |
Correct |
67 ms |
8192 KB |
Output is correct |
29 |
Correct |
85 ms |
8232 KB |
Output is correct |
30 |
Correct |
81 ms |
8308 KB |
Output is correct |
31 |
Correct |
82 ms |
8392 KB |
Output is correct |
32 |
Correct |
81 ms |
8288 KB |
Output is correct |
33 |
Correct |
84 ms |
8252 KB |
Output is correct |