# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
393004 |
2021-04-22T14:01:50 Z |
Mlxa |
Shopping (JOI21_shopping) |
C++14 |
|
407 ms |
97368 KB |
#include "Anna.h"
#include <bits/stdc++.h>
using namespace std;
namespace local {
const int UP = 0, LEF = 2, RIG = 3;
int n, l, r, choice = -1;
vector<int> q;
}
void InitA(int nn, int ll, int rr) {
using namespace local;
n = nn;
l = ll;
r = rr;
}
void solve() {
using namespace local;
int v = 0, ql = 0, qr = 0;
for (int i = 0; i < 20; ++i) {
v += q[i] << i;
ql += q[i + 20] << i;
qr += q[i + 40] << i;
}
// cout << "? " << v << " " << ql << " " << qr << endl;
if (!(ql <= l && r <= qr)) {
SendA(0);
return;
}
if (r < v) {
SendA(1), SendA(0);
return;
}
if (l > v) {
SendA(1), SendA(1);
return;
}
choice = v;
}
void ReceiveA(bool x) {
using namespace local;
q.push_back(x);
if ((int)q.size() == 60) {
solve();
q.clear();
}
}
int Answer() {
using namespace local;
assert(choice != -1);
return choice;
}
#include "Bruno.h"
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
namespace my {
const int N = 1 << 20;
const int INF = 1e9;
bool bad[N];
pair<int, int> t[2 * N];
int query(int l, int r) {
pair<int, int> res = make_pair(INF, -1);
for (l += N, r += N; l <= r; l /= 2, r /= 2) {
if (l % 2 == 1) {
res = min(res, t[l++]);
}
if (r % 2 == 0) {
res = min(res, t[r--]);
}
}
return res.y;
}
vector<pair<int, int>> g[N];
int lb[N], rb[N];
const int UP = 0;
const int LEF = 2;
const int RIG = 3;
int pdfs(int l, int r) {
int v = query(l, r);
lb[v] = l, rb[v] = r;
if (l < v) {
int u = pdfs(l, v - 1);
g[v].emplace_back(u, LEF);
g[u].emplace_back(v, UP);
}
if (v < r) {
int u = pdfs(v + 1, r);
g[v].emplace_back(u, RIG);
g[u].emplace_back(v, UP);
}
return v;
}
int sz[N];
void szdfs(int v, int p) {
sz[v] = 1;
for (auto e : g[v]) {
int u = e.x;
if (u == p || bad[u]) {
continue;
}
szdfs(u, v);
sz[v] += sz[u];
}
}
int cdfs(int v, int p, int s) {
for (auto e : g[v]) {
int u = e.x;
if (u == p || bad[u]) {
continue;
}
if (2 * sz[u] > s) {
return cdfs(u, v, s);
}
}
return v;
}
int center(int v) {
szdfs(v, v);
return cdfs(v, v, sz[v]);
}
void send(int len, int msk) {
for (int i = 0; i < len; ++i) {
SendB((msk >> i) & 1);
}
}
void ask(int v) {
send(20, v);
send(20, lb[v]);
send(20, rb[v]);
}
int root;
int state = -1;
}
void InitB(int n, vector<int> p) {
using namespace my;
for (int i = 0; i < n; ++i) {
t[N + i] = make_pair(p[i], i);
}
for (int i = N - 1; i > 0; --i) {
t[i] = min(t[i + i], t[i + i + 1]);
}
root = pdfs(0, n - 1);
root = center(root);
bad[root] = true;
ask(root);
}
void ReceiveB(bool y) {
// cout << "ReceiveB " << y << endl;
using namespace my;
if (state == -1) {
state = y;
} else if (state == 1) {
state = 2 + y;
} else {
assert(false);
}
if (state == 0 || state == 2 || state == 3) {
for (auto e : g[root]) {
if (e.y == state) {
root = e.x;
break;
}
}
// cout << "go to " << root << endl;
root = center(root);
bad[root] = true;
ask(root);
state = -1;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
33304 KB |
Output is correct |
2 |
Correct |
25 ms |
33280 KB |
Output is correct |
3 |
Correct |
24 ms |
33312 KB |
Output is correct |
4 |
Correct |
25 ms |
33280 KB |
Output is correct |
5 |
Correct |
25 ms |
33352 KB |
Output is correct |
6 |
Correct |
29 ms |
33336 KB |
Output is correct |
7 |
Correct |
30 ms |
33420 KB |
Output is correct |
8 |
Correct |
25 ms |
33412 KB |
Output is correct |
9 |
Correct |
29 ms |
33408 KB |
Output is correct |
10 |
Correct |
30 ms |
33304 KB |
Output is correct |
11 |
Correct |
29 ms |
33408 KB |
Output is correct |
12 |
Correct |
32 ms |
33472 KB |
Output is correct |
13 |
Correct |
29 ms |
33428 KB |
Output is correct |
14 |
Correct |
30 ms |
33392 KB |
Output is correct |
15 |
Correct |
27 ms |
33408 KB |
Output is correct |
16 |
Correct |
26 ms |
33408 KB |
Output is correct |
17 |
Correct |
25 ms |
33408 KB |
Output is correct |
18 |
Correct |
31 ms |
33420 KB |
Output is correct |
19 |
Correct |
29 ms |
33364 KB |
Output is correct |
20 |
Correct |
26 ms |
33412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
33304 KB |
Output is correct |
2 |
Correct |
25 ms |
33280 KB |
Output is correct |
3 |
Correct |
24 ms |
33312 KB |
Output is correct |
4 |
Correct |
25 ms |
33280 KB |
Output is correct |
5 |
Correct |
25 ms |
33352 KB |
Output is correct |
6 |
Correct |
29 ms |
33336 KB |
Output is correct |
7 |
Correct |
30 ms |
33420 KB |
Output is correct |
8 |
Correct |
25 ms |
33412 KB |
Output is correct |
9 |
Correct |
29 ms |
33408 KB |
Output is correct |
10 |
Correct |
30 ms |
33304 KB |
Output is correct |
11 |
Correct |
29 ms |
33408 KB |
Output is correct |
12 |
Correct |
32 ms |
33472 KB |
Output is correct |
13 |
Correct |
29 ms |
33428 KB |
Output is correct |
14 |
Correct |
30 ms |
33392 KB |
Output is correct |
15 |
Correct |
27 ms |
33408 KB |
Output is correct |
16 |
Correct |
26 ms |
33408 KB |
Output is correct |
17 |
Correct |
25 ms |
33408 KB |
Output is correct |
18 |
Correct |
31 ms |
33420 KB |
Output is correct |
19 |
Correct |
29 ms |
33364 KB |
Output is correct |
20 |
Correct |
26 ms |
33412 KB |
Output is correct |
21 |
Correct |
35 ms |
33932 KB |
Output is correct |
22 |
Correct |
27 ms |
33980 KB |
Output is correct |
23 |
Correct |
37 ms |
34040 KB |
Output is correct |
24 |
Correct |
27 ms |
33960 KB |
Output is correct |
25 |
Correct |
38 ms |
33964 KB |
Output is correct |
26 |
Correct |
34 ms |
33920 KB |
Output is correct |
27 |
Correct |
35 ms |
34688 KB |
Output is correct |
28 |
Correct |
34 ms |
34688 KB |
Output is correct |
29 |
Correct |
32 ms |
34432 KB |
Output is correct |
30 |
Correct |
33 ms |
33960 KB |
Output is correct |
31 |
Correct |
28 ms |
33920 KB |
Output is correct |
32 |
Correct |
27 ms |
33956 KB |
Output is correct |
33 |
Correct |
28 ms |
34168 KB |
Output is correct |
34 |
Correct |
33 ms |
33984 KB |
Output is correct |
35 |
Correct |
31 ms |
33980 KB |
Output is correct |
36 |
Correct |
33 ms |
33920 KB |
Output is correct |
37 |
Correct |
35 ms |
34008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
407 ms |
96516 KB |
Output is correct |
2 |
Correct |
383 ms |
97368 KB |
Output is correct |
3 |
Failed |
11 ms |
260 KB |
Expected integer, but "Wrong" found (Anna) |
4 |
Halted |
0 ms |
0 KB |
- |