# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935604 | wii | Ancient Machine (JOI21_ancient_machine) | C++17 | 47 ms | 8308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
void Anna(int N, std::vector<char> S);
void Send(int a);
void Anna(int N, std::vector<char> S) {
const int Lim = 87;
const int LOG = 61;
int cnt[3] = {0};
for (char x: S) {
if (x == 'X') ++cnt[0];
if (x == 'Y') ++cnt[1];
if (x == 'Z') ++cnt[2];
}
vector<int> a;
a.assign(N, 0);
int res = 0;
for (int i = 0; i < N; ++i)
if (S[i] == 'X') {
res = i; break;
}
for (int i = 1; i <= 17; ++i)
Send(res >> i - 1 & 1);
for (int i = 0; i < N; ++i) if (i > res)
a[i] = (S[i] == 'Z');
for (int i = 1; i < N; ++i)
if (a[i - 1] == 1 && a[i] == 1)
a[i - 1] = 0;
vector<ll> fibo(95);
fibo[0] = 1; fibo[1] = 1;
for (int i = 2; i <= Lim; ++i)
fibo[i] = fibo[i - 1] + fibo[i - 2];
for (int i = 0; i < N; i += Lim) {
ll hash_num = 0;
for (int j = i; j < N && j < i + Lim; ++j)
if (a[j] == 1)
hash_num += fibo[j - i + 1];
for (int u = 1; u <= LOG; ++u)
Send(hash_num >> u - 1 & 1);
}
}
#include <deque>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
void Bruno(int N, int L, std::vector<int> A);
void Remove(int d);
// 11 XYZXZYXYXYZ
void Bruno(int N, int L, std::vector<int> A) {
const int Lim = 87;
const int LOG = 61;
int ptr = 0;
int first_x = 0;
for (int i = 1; i <= 17; ++i) {
if (A[ptr] == 1)
first_x += 1LL << i - 1;
++ptr;
}
vector<int> pos_z;
pos_z.push_back(first_x);
vector<ll> fibo(95);
fibo[0] = 1; fibo[1] = 1;
for (int i = 2; i <= Lim; ++i)
fibo[i] = fibo[i - 1] + fibo[i - 2];
int cur = 0;
for (int i = ptr; i < A.size(); i += LOG) {
ll hash_num = 0;
for (int j = 1; j <= LOG && i + j - 1 < A.size(); ++j)
if (A[i + j - 1] == 1)
hash_num += 1LL << j - 1;
for (int u = Lim ; u >= 1; --u) if (hash_num >= fibo[u]) {
pos_z.push_back(cur + u - 1);
hash_num -= fibo[u];
} cur += Lim;
} sort(pos_z.begin(), pos_z.end());
for (int i = 1; i < pos_z.size(); ++i) {
int l = pos_z[i - 1];
int r = pos_z[i];
// cout << l << " " << r << "\n";
for (int u = r - 1; u > l; --u)
Remove(u);
Remove(r);
}
for (int i = pos_z.back() + 1; i < N; ++i)
Remove(i);
for (int i = 0; i <= pos_z[0]; ++i)
Remove(i);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |