#include "Anna.h"
#include <vector>
#include <iostream>
using namespace std;
#define ll long long
bool DEBUG1 = false;
int bitlen1 = 50;
namespace {
vector<ll> fib;
void initFib() {
fib.push_back(1);
fib.push_back(1);
for (int i = 2; i <= 66; ++i){
fib.push_back(fib[i-2] + fib[i-1]);
}
}
//0000000000001010001010100001010000010001001000001000001010000001
//0000000000001010001010100001010000010001001000001000001010000010
ll handleArray(string& b, int l, int r) {
ll score = 0;
for (int i = l; i < r; ++i){
score += ((ll)b[i]) * (ll)fib[r-i];
}
return score;
}
void sendSignals(ll x){
for (int i = bitlen1-1; i >= 0; --i){
Send((x >> i) & 1);
}
}
}
void Anna(int N, vector<char> S) {
initFib();
int len = ((N + 63) / 64)*64;
string b(len, 0);
int i = -1;
while (++i < N && S[i] != 'X');
if (i == N){
Send(1);
return;
}
b[i++] = 1;
++i;
for (; i < N; ++i){
if (i + 1 < N && S[i] == S[i+1]){
continue;
}
b[i] = (S[i] == 'Z')?1:0;
}
auto hashValue = std::hash<std::string>{}(b);
for (int i = 0; i != 64; ++i){
Send((hashValue >> i) & 1);
}
if (DEBUG1){
std::cout << "sent hash " << hashValue << endl;
std::cout << "code" << endl;
int i = 0;
for (char c : b){
cout << int(c);
if (++i % 64 == 0) {
cout << endl;
}
}
cout << endl;
}
for (int l = 0; l < N; l += 64){
ll permutation = handleArray(b, l, l+64);
if (DEBUG1){
cout << "Anna = " << permutation << endl;
}
sendSignals(permutation);
}
if (DEBUG1){
string s1 = "0000000000001010001010100001010000010001001000001000001010000001";
for (char&c : s1) {
c -= '0';
}
string s2 = "0000000000001010001010100001010000010001001000001000001010000010";
for (char&c : s2){
c -= '0';
}
cout << "Fibo of s1= " << handleArray(s1,0, 64) << " size = " << s1.size() <<endl;
cout << "Fibo of s2= " << handleArray(s2,0, 64)<< " size = " << s2.size() << endl;
}
}
#include "Bruno.h"
#include <vector>
#include <iostream>
using namespace std;
#define ll long long
bool DEBUG = false;
namespace {
int bitlen = 50;
vector<ll> fib;
void initFib() {
fib.push_back(1);
fib.push_back(1);
for (int i = 2; i <= 66; ++i){
fib.push_back(fib[i-2] + fib[i-1]);
}
}
ll getNumber(vector<int> & a, int start){
ll ans = 0;
for (int i = start; i < start + bitlen; ++i){
ans <<= 1;
ans += a[i];
}
return ans;
}
//0000000000001010001010100001010000010001001000001000001010000001
//0000000000001010001010100001010000010001001000001000001010000010
void deriveSequence(ll number, string & result){
for (int i = 64; i >= 1; --i){
if (fib[i] <= number){
number -= fib[i];
result += char(1);
}
else{
result += char(0);
}
}
}
}
void Bruno(int N, int L, std::vector<int> A) {
if (L == 1){
for (int i = 0; i < N; ++i){
Remove(i);
}
return;
}
initFib();
std::size_t hashValue = 0;
for (int i = 0; i != 64; ++i){
hashValue |= ((size_t)A[i] << i);
}
string result;
for (int l = 64; l < L; l += bitlen){
ll number = getNumber(A, l);
if (DEBUG){
cout << "Bruno number = " << number << endl;
}
deriveSequence(number, result);
}
if (DEBUG) {
std::cout << "get hash = " << hashValue << endl;
for (int i = 0; i != 64; ++i){
std::cout << A[63-i];
}
cout << endl;
cout << "Code got " << endl;
int i = 0;
for (char c : result){
cout << int(c);
if (++i % 64 == 0){
cout << endl;
}
}
cout << endl;
}
size_t getHash = std::hash<std::string>{}(result);
if (DEBUG) {
cout << "Cal hash = " << getHash << endl;
}
if (getHash != hashValue){
Remove(-1);
if (DEBUG) {
cout << "Get wrong data: " << hashValue << " " << getHash << endl;
}
return;
}
vector<int> ones;
for (int i = 0; i < result.size(); ++i){
if (result[i] == 1){
ones.push_back(i);
}
}
// PreX
for (int i =0; i != ones.front();++i){
Remove(i);
}
for (int i = 1; i < ones.size(); ++i){
for (int j = ones[i]-1; j > ones[i-1]; --j){
Remove(j);
}
Remove(ones[i]);
}
Remove(ones[0]);
for (int j = ones.back()+1; j < N; ++j){
Remove(j);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |