# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
708692 | ntdxl05 | Ancient Machine (JOI21_ancient_machine) | C++17 | 40 ms | 2564 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 <bits/stdc++.h>
#include "Anna.h"
#include <vector>
using namespace std;
namespace {
const int dc[] = {'X', 'Y', 'Z'};
int idc[256];
int variable_example = 0;
}
void Anna(int N, std::vector<char> S) {
for (int i = 0; i < 3; i++) idc[dc[i]] = i;
if (N <= 18) {
for (int i = 0; i < N; i++) {
Send(idc[S[i]] >> 1 & 1);
Send(idc[S[i]] & 1);
}
return ;
}
}
#include <bits/stdc++.h>
#include "Bruno.h"
#include <vector>
using namespace std;
namespace {
const int dc[] = {'X', 'Y', 'Z'};
int idc[256];
int variable_example = 0;
const int inf = 1e9;
int FunctionExample(int P) { return 1 - P; }
template<class U, class V>
bool minz(U &a, V b) {
if (a > b) return a = b, 1;
return 0;
}
template<class U, class V>
bool maxz(U &a, V b) {
if (a < b) return a = b, 1;
return 0;
}
} // namespace
void Bruno(int N, int L, std::vector<int> A) {
for (int i = 0; i < L; i++) {
variable_example += FunctionExample(A[i]);
}
vector<char> S(N);
for (int i = 0; i < N; i++) S[i] = dc[A[i << 1] << 1 | A[i << 1 | 1]];
vector<int> dp(1 << N), trc(1 << N);
dp[0] = 0;
for (int msk = 0; msk < (1 << N) - 1; msk++) {
vector<int> b(N);
for (int i = 0; i < N; i++) b[i] = msk >> i & 1;
for (int i = 0; i < N; i++) {
if (b[i]) continue;
int l = i - 1, r = i + 1;
for (; ~l && !b[l]; l--);
for (; r < N && !b[r]; r++);
bool e = ~l && r < N && S[i] == 'Y' && S[l] == 'X' && S[r] == 'Z';
if (maxz(dp[msk | 1 << i], dp[msk] + e)) trc[msk | 1 << i] = i;
}
}
int cr = (1 << N) - 1;
while (cr) {
auto &t = trc[cr];
Remove(t);
cr ^= 1 << t;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |