# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
709631 | lmqzzz | 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"
#include <bits/stdc++.h>
using namespace std;
void send(int x) {
bitset<17> a(x);
for (int i = 0; i < 17; i++) Send(a[i]);
}
int f[1 << 18];
int trace[1 << 18];
void Anna(int N, std::vector<char> S) {
string temp = "XYZ";
memset(f, -1, sizeof f);
f[0] = 0;
trace[0] = -1;
for (int i = 0; i < 1 << N; i++) {
for (int j = 0; j < N; j++) {
if (i >> j & 1 ^ 1) {
bool okl = 0, okr = 0, okm = S[j] == 'Y';
for (int k = j - 1; k >= 0; k--) {
if (i >> k & 1 ^ 1) {
okl = S[k] == 'X';
break;
}
}
for (int k = j + 1; k < N; k++) {
if (i >> k & 1 ^ 1) {
okr = S[k] == 'Z';
break;
}
}
if (f[i | (1 << j)] < f[i] + (okl && okr && okm)) {
f[i | (1 << j)] = f[i] + (okl && okr && okm);
trace[i | (1 << j)] = j;
}
}
}
}
int cur = (1 << N) - 1;
vector<int> ans;
while (trace[cur] != -1) {
cerr << cur << ' ';
ans.emplace_back(trace[cur]);
cur ^= 1 << trace[cur];
}
reverse(ans.begin(), ans.end());
for (int x : ans) send(x);
}
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
void send(int x) {
bitset<17> a(x);
for (int i = 0; i < 17; i++) Send(a[i]);
}
int f[1 << 18];
int trace[1 << 18];
void Anna(int N, std::vector<char> S) {
string temp = "XYZ";
memset(f, -1, sizeof f);
f[0] = 0;
trace[0] = -1;
for (int i = 0; i < 1 << N; i++) {
for (int j = 0; j < N; j++) {
if (i >> j & 1 ^ 1) {
bool okl = 0, okr = 0, okm = S[j] == 'Y';
for (int k = j - 1; k >= 0; k--) {
if (i >> k & 1 ^ 1) {
okl = S[k] == 'X';
break;
}
}
for (int k = j + 1; k < N; k++) {
if (i >> k & 1 ^ 1) {
okr = S[k] == 'Z';
break;
}
}
if (f[i | (1 << j)] < f[i] + (okl && okr && okm)) {
f[i | (1 << j)] = f[i] + (okl && okr && okm);
trace[i | (1 << j)] = j;
}
}
}
}
int cur = (1 << N) - 1;
vector<int> ans;
while (trace[cur] != -1) {
cerr << cur << ' ';
ans.emplace_back(trace[cur]);
cur ^= 1 << trace[cur];
}
reverse(ans.begin(), ans.end());
for (int x : ans) send(x);
}