# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
417320 | lyc | Ancient Machine (JOI21_ancient_machine) | C++17 | 58 ms | 2980 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 <vector>
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef pair<int,int> ii;
namespace {
int N, res[1<<18], pa[1<<18];
vector<char> S;
int dp(int x) {
if (x == 0) return 0;
if (~res[x]) return res[x];
res[x] = -1;
for (int y = x; y;) {
int b = y&-y, j = __builtin_ctz(b);
int add = 0;
if (S[j] == 'Y') {
int p = x & ((1<<j)-1), q = x ^ p ^ b;
if (p != 0 && q != 0) {
int r = 31-__builtin_clz(p), s = __builtin_ctz(q);
if (S[r] == 'X' && S[s] == 'Z') ++add;
}
}
int cur = dp(x ^ b) + add;
if (cur > res[x]) {
pa[x] = j;
res[x] = cur;
}
y ^= b;
}
return res[x];
}
}
void Anna(int _N, std::vector<char> _S) {
N = _N;
S = _S;
memset(res,-1,sizeof res);
memset(pa,-1,sizeof pa);
dp((1<<N)-1);
vector<int> seq;
int u = (1<<N)-1;
while (pa[u] != -1) {
seq.push_back(pa[u]);
u = u ^ (1<<pa[u]);
}
//cout << "SEQ ";
for (int& x : seq) {
//cout << x << '\n';
RFOR(i,4,0){
Send((x&(1<<i)) > 0);
}
}
}
#include "Bruno.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long ll;
typedef pair<int,int> ii;
namespace {
} // namespace
void Bruno(int N, int L, std::vector<int> A) {
int p = 0;
FOR(i,0,N-1){
int x = 0;
FOR(j,0,4){
x *= 2;
x += A[p++];
}
Remove(x);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |