# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
752178 | Sam_a17 | Ancient Machine (JOI21_ancient_machine) | C++17 | 0 ms | 0 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 "Anna.h"
void Send(int a);
void Anna(int N, std::vector<char> S) {
Send(0);
for(int i = 0; i < N; i++) {
if(S[i] == 'X') {
Send(0);
} else if(S[i] == 'Y') {
Send(1);
Send(0);
} else {
Send(1);
Send(1);
Send(0);
}
}
}
#include "Bruno.h"
void Remove(int d);
void Bruno(int N, int L, std::vector<int> A) {
vector<int> a;
for(int i = 0; i < L - 1; i++) {
assert(A[i] == 0);
int j = i + 1, cnt = 0;
while(j < L && A[j] == 1) {
j++, cnt++;
}
if(cnt == 0) {
a.push_back(0);
} else if(cnt == 1) {
a.push_back(1);
} else {
a.push_back(2);
}
i = j - 1;
}
set<int> st[3];
auto dll = [&](int l, int r)-> void {
for(int i = 0; i < 3; i++) {
auto it = st[i].lower_bound(l);
vector<int> to_del;
while(it != st[i].end() && *it < r) {
to_del.push_back(*it);
it = next(it);
}
for(auto j: to_del) {
Remove(j);
st[i].erase(j);
}
}
};
for (int i = 0; i < N; i++) {
int ok = 0;
if(a[i] == 2) {
if(!st[1].empty() && !st[0].empty()) {
auto itr = *st[1].rbegin();
auto itl = *st[0].begin();
if(itl < itr) {
dll(itr + 1, i);
itl = *st[0].rbegin();
dll(itl + 1, itr);
//
st[1].erase(prev(st[1].end()));
Remove(itr);
ok = 1;
}
}
}
st[a[i]].insert(i);
}
for(int i = 0; i < 3; i++) {
for(auto j: st[i]) {
Remove(j);
}
}
}