#include "Anna.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
namespace
{
int N, L, R;
int cnt;
vector<int> status;
int res;
stack<int> s;
vector<int> Left;
vector<int> Right;
int last = -1;
int root = 0;
int sz = 0;
int idxmid = 0;
} // namespace
void InitA(int N, int L, int R)
{
::N = N;
::L = L;
::R = R;
res = L;
Left.resize(1957 * 2 + 1, -1);
Right.resize(1957 * 2 + 1, -1);
cnt = 0;
int l = L / 1957;
int r = R / 1957;
for (int i = 0; i <= 8; i++)
{
if ((l >> i) & 1)
{
SendA(1);
}
else
{
SendA(0);
}
}
for (int i = 0; i <= 8; i++)
{
if ((r >> i) & 1)
{
SendA(1);
}
else
{
SendA(0);
}
}
if (r == l)
{
sz = min(1957, N);
}
else
{
sz = 1957 + min(1957, N - (r * 1957)) + 1;
}
// cout << L << ' ' << R << endl;
}
int get_idx(int idx)
{
if (L / 1957 == R / 1957)
{
return ((L / 1957) * 1957) + idx;
}
if (idx < 1957)
{
return ((L / 1957) * 1957) + idx;
}
else if (idx == sz - 1)
{
return idxmid;
}
else
{
return ((R / 1957) * 1957) + idx - 1957;
}
}
void solve()
{
// for (int i = 0; i < sz; i++)
// {
// cout << i << " " << Left[i] << " " << Right[i] << endl;
// }
int e = get_idx(root);
// cout << root << endl;
while (e > R || e < L)
{
if (e > R)
{
root = Left[root];
}
else
{
root = Right[root];
}
e = get_idx(root);
}
res = e;
}
void ReceiveA(bool x)
{
// cout << "Hello" << endl;
if (cnt < sz)
{
if (x)
{
last = s.top();
s.pop();
}
else
{
if (s.empty())
{
if (cnt)
{
Left[cnt] = last;
}
root = cnt;
s.push(cnt);
}
else if (last == -1)
{
Right[s.top()] = cnt;
s.push(cnt);
}
else
{
Left[cnt] = last;
Right[s.top()] = cnt;
s.push(cnt);
}
last = -1;
cnt++;
}
}
else
{
if (x)
idxmid += pow(2, cnt - sz);
cnt++;
}
// cout << cnt << endl;
if ((cnt == sz + 20 && L / 1957 != R / 1957) || (cnt == sz && L / 1957 == R / 1957))
{
solve();
}
}
int Answer()
{
return res;
}
#include "Bruno.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
namespace
{
int N;
vector<int> nums;
int cnt = 0;
int L = 0;
int R = 0;
}
void minel()
{
vector<int> v;
int idxmid = -1;
if (L == R)
{
for (int i = L * 1957; i <= min((L * 1957) + 1956, N - 1); i++)
{
// cout << i << endl;
v.push_back(nums[i]);
}
}
else
{
for (int i = L * 1957; i <= (L * 1957) + 1956; i++)
{
v.push_back(nums[i]);
}
for (int i = R * 1957; i <= min((R * 1957) + 1956, N - 1); i++)
{
v.push_back(nums[i]);
}
int mn = 1e7;
for (int i = (L * 1957) + 1957; i < R * 1957; i++)
{
if (nums[i] < mn)
{
mn = nums[i];
idxmid = i;
}
}
v.push_back(mn);
}
/////////
int n = v.size();
int root = -1;
stack<int> s;
vector<int> left(n, -1);
vector<int> right(n, -1);
// cout << n << endl;
for (int i = 0; i < n; i++)
{
if (s.empty())
{
root = i;
s.push(i);
SendB(0);
continue;
}
int last = -1;
while (!s.empty() && v[s.top()] > v[i])
{
last = s.top();
s.pop();
SendB(1);
}
if (last == -1)
{
right[s.top()] = i;
s.push(i);
SendB(0);
}
else if (s.empty())
{
left[i] = last;
root = i;
s.push(i);
SendB(0);
}
else
{
left[i] = last;
right[s.top()] = i;
s.push(i);
SendB(0);
}
}
// for (int i = 0; i < n; i++)
// {
// cout << i << " " << left[i] << " " << right[i] << endl;
// }
if (L != R)
{
for (int i = 0; i < 20; i++)
{
if ((idxmid >> i) & 1)
{
SendB(1);
}
else
{
SendB(0);
}
}
}
}
void InitB(int N, std::vector<int> P)
{
::N = N;
nums = P;
}
void ReceiveB(bool y)
{
if (cnt <= 8)
{
if (y)
L += pow(2, cnt);
cnt++;
}
else if (cnt <= 16)
{
if (y)
R += pow(2, cnt - 9);
cnt++;
}
else
{
// cout << L << " " << R << endl;
minel();
}
}
Compilation message
Bruno.cpp: In function 'void minel()':
Bruno.cpp:52:7: warning: variable 'root' set but not used [-Wunused-but-set-variable]
52 | int root = -1;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
1 ms |
400 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
0 ms |
400 KB |
Output is correct |
5 |
Correct |
1 ms |
400 KB |
Output is correct |
6 |
Correct |
22 ms |
400 KB |
Output is correct |
7 |
Correct |
13 ms |
400 KB |
Output is correct |
8 |
Correct |
16 ms |
400 KB |
Output is correct |
9 |
Correct |
9 ms |
404 KB |
Output is correct |
10 |
Correct |
12 ms |
400 KB |
Output is correct |
11 |
Correct |
7 ms |
400 KB |
Output is correct |
12 |
Correct |
5 ms |
636 KB |
Output is correct |
13 |
Correct |
13 ms |
508 KB |
Output is correct |
14 |
Correct |
9 ms |
400 KB |
Output is correct |
15 |
Correct |
12 ms |
400 KB |
Output is correct |
16 |
Correct |
13 ms |
400 KB |
Output is correct |
17 |
Correct |
13 ms |
400 KB |
Output is correct |
18 |
Correct |
18 ms |
400 KB |
Output is correct |
19 |
Correct |
12 ms |
400 KB |
Output is correct |
20 |
Correct |
19 ms |
400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
456 KB |
Output is correct |
2 |
Correct |
1 ms |
400 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
0 ms |
400 KB |
Output is correct |
5 |
Correct |
1 ms |
400 KB |
Output is correct |
6 |
Correct |
22 ms |
400 KB |
Output is correct |
7 |
Correct |
13 ms |
400 KB |
Output is correct |
8 |
Correct |
16 ms |
400 KB |
Output is correct |
9 |
Correct |
9 ms |
404 KB |
Output is correct |
10 |
Correct |
12 ms |
400 KB |
Output is correct |
11 |
Correct |
7 ms |
400 KB |
Output is correct |
12 |
Correct |
5 ms |
636 KB |
Output is correct |
13 |
Correct |
13 ms |
508 KB |
Output is correct |
14 |
Correct |
9 ms |
400 KB |
Output is correct |
15 |
Correct |
12 ms |
400 KB |
Output is correct |
16 |
Correct |
13 ms |
400 KB |
Output is correct |
17 |
Correct |
13 ms |
400 KB |
Output is correct |
18 |
Correct |
18 ms |
400 KB |
Output is correct |
19 |
Correct |
12 ms |
400 KB |
Output is correct |
20 |
Correct |
19 ms |
400 KB |
Output is correct |
21 |
Correct |
41 ms |
528 KB |
Output is correct |
22 |
Correct |
25 ms |
588 KB |
Output is correct |
23 |
Correct |
28 ms |
624 KB |
Output is correct |
24 |
Correct |
46 ms |
528 KB |
Output is correct |
25 |
Correct |
24 ms |
528 KB |
Output is correct |
26 |
Correct |
22 ms |
616 KB |
Output is correct |
27 |
Correct |
33 ms |
752 KB |
Output is correct |
28 |
Correct |
46 ms |
620 KB |
Output is correct |
29 |
Correct |
62 ms |
724 KB |
Output is correct |
30 |
Correct |
39 ms |
588 KB |
Output is correct |
31 |
Correct |
56 ms |
528 KB |
Output is correct |
32 |
Correct |
49 ms |
528 KB |
Output is correct |
33 |
Correct |
25 ms |
752 KB |
Output is correct |
34 |
Correct |
25 ms |
528 KB |
Output is correct |
35 |
Correct |
25 ms |
588 KB |
Output is correct |
36 |
Correct |
22 ms |
584 KB |
Output is correct |
37 |
Correct |
35 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
50 ms |
284 KB |
Wrong Answer [2] |
2 |
Halted |
0 ms |
0 KB |
- |