# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1101159 | rainboy | Flights (JOI22_flights) | C++17 | 225 ms | 1828 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 "Ali.h"
#include <cstring>
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
namespace Ali {
const int N = 10000, B = 10, L = 14; /* L = ceil(log2(N)) */
int min(int a, int b) { return a < b ? a : b; }
void encode(string &aa, int i_, int n, int x) {
for (int i = 0; i < n; i++)
aa[i_ + i] = (x >> i & 1) + '0';
}
int decode(string &aa, int i_, int n) {
int x = 0;
for (int i = 0; i < n; i++)
if (aa[i_ + i] == '1')
x |= 1 << i;
return x;
}
int ej[N][3], eo[N], n;
void append(int i, int j) {
ej[i][eo[i]++] = j;
}
void init(vi ii, vi jj, int n_) {
n = n_;
memset(eo, 0, n * sizeof *eo);
for (int i = 0; i < n; i++)
eo[i] = 0;
for (int h = 0; h < n - 1; h++)
append(ii[h], jj[h]), append(jj[h], ii[h]);
for (int i = 0; i < n; i++)
SetID(i, i);
}
int dd[N];
void dfs(int p, int i, int d) {
dd[i] = d;
for (int o = eo[i]; o--; ) {
int j = ej[i][o];
if (j != p)
dfs(i, j, d + 1);
}
}
string send(string bb) {
int u_ = decode(bb, 0, 10), v_ = decode(bb, 10, 10);
int ul = u_ * B, ur = min((u_ + 1) * B, n), vl = v_ * B, vr = min((v_ + 1) * B, n);
string cc((ur - ul) * (vr - vl) * L, '?');
for (int u = ul; u < ur; u++) {
dfs(-1, u, 0);
for (int v = vl; v < vr; v++)
encode(cc, ((u - ul) * (vr - vl) + (v - vl)) * L, L, dd[v]);
}
return cc;
}
}
void Init(int n, vi ii, vi jj) {
Ali::init(ii, jj, n);
}
string SendA(string bb) {
return Ali::send(bb);
}
#include "Benjamin.h"
#include <string>
#include <vector>
using namespace std;
typedef vector<int> vi;
namespace Benjamin {
const int N = 10000, B = 10, L = 14; /* L = ceil(log2(N)) */
int min(int a, int b) { return a < b ? a : b; }
void encode(string &aa, int i_, int n, int x) {
for (int i = 0; i < n; i++)
aa[i_ + i] = (x >> i & 1) + '0';
}
int decode(string &aa, int i_, int n) {
int x = 0;
for (int i = 0; i < n; i++)
if (aa[i_ + i] == '1')
x |= 1 << i;
return x;
}
int n, u, v, u_, v_;
string SendB(int n_, int u__, int v__) {
n = n_, u = u__, v = v__, u_ = u / B, v_ = v / B;
string bb(20, '?');
encode(bb, 0, 10, u_), encode(bb, 10, 10, v_);
return bb;
}
int Answer(string aa) {
int ul = u_ * B, vl = v_ * B, vr = min((v_ + 1) * B, n);
return decode(aa, ((u - ul) * (vr - vl) + (v - vl)) * L, L);
}
}
string SendB(int n, int u, int v) {
return Benjamin::SendB(n, u, v);
}
int Answer(string aa) {
return Benjamin::Answer(aa);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |