//By Don4ick
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include "xylophone.h"
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
#define forn(i, n) for (int i = 1; i <= n; i++)
#define pb push_back
#define all(x) x.begin(), x.end()
#define y1 qwer1234
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
using namespace std;
void solve(int n) {
int pos = -1;
//~binary_search
{
int l = 0, r = n + 1;
while(l < r - 1)
{
int mid = (l + r) >> 1;
if (query(mid, n) == n - 1)
l = mid;
else
r = mid;
}
pos = l;
}
answer(pos, 1);
//~solve(1, pos)
if (pos > 1)
{
int y = 1, x = query(pos - 1, pos) + 1;
answer(pos - 1, x);
for (int i = pos - 2; i >= 1; i--)
{
int value = query(i, i + 2);
if (value > abs(x - y))
{
int newValue = query(i, i + 1);
if (x < y)
{
if (newValue == value)
{
y = x + value;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
else
{
if (newValue == value)
{
y = x - value;
swap(x, y);
answer(i, x);
}
else
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
}
}
else
{
int newValue = query(i, i + 1);
if (x < y)
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
}
}
//~solve(pos, n)
if (pos < n)
{
int y = 1, x = query(pos, pos + 1) + 1;
answer(pos + 1, x);
for (int i = pos + 2; i <= n; i++)
{
int value = query(i - 2, i);
if (value > abs(x - y))
{
int newValue = query(i - 1, i);
if (x < y)
{
if (newValue == value)
{
y = x + value;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
else
{
if (newValue == value)
{
y = x - value;
swap(x, y);
answer(i, x);
}
else
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
}
}
else
{
int newValue = query(i - 1, i);
if (x < y)
{
y = x + newValue;
swap(x, y);
answer(i, x);
}
else
{
y = x - newValue;
swap(x, y);
answer(i, x);
}
}
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
4 |
Correct |
5 ms |
440 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
584 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
5 ms |
584 KB |
Output is correct |
9 |
Correct |
5 ms |
584 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
4 ms |
584 KB |
Output is correct |
12 |
Correct |
5 ms |
584 KB |
Output is correct |
13 |
Correct |
4 ms |
584 KB |
Output is correct |
14 |
Correct |
4 ms |
584 KB |
Output is correct |
15 |
Correct |
4 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
4 |
Correct |
5 ms |
440 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
584 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
5 ms |
584 KB |
Output is correct |
9 |
Correct |
5 ms |
584 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
4 ms |
584 KB |
Output is correct |
12 |
Correct |
5 ms |
584 KB |
Output is correct |
13 |
Correct |
4 ms |
584 KB |
Output is correct |
14 |
Correct |
4 ms |
584 KB |
Output is correct |
15 |
Correct |
4 ms |
584 KB |
Output is correct |
16 |
Correct |
7 ms |
584 KB |
Output is correct |
17 |
Correct |
11 ms |
584 KB |
Output is correct |
18 |
Correct |
15 ms |
584 KB |
Output is correct |
19 |
Correct |
26 ms |
584 KB |
Output is correct |
20 |
Correct |
17 ms |
584 KB |
Output is correct |
21 |
Correct |
24 ms |
584 KB |
Output is correct |
22 |
Correct |
23 ms |
584 KB |
Output is correct |
23 |
Correct |
12 ms |
584 KB |
Output is correct |
24 |
Correct |
25 ms |
584 KB |
Output is correct |
25 |
Correct |
19 ms |
584 KB |
Output is correct |
26 |
Correct |
20 ms |
584 KB |
Output is correct |
27 |
Correct |
19 ms |
584 KB |
Output is correct |
28 |
Correct |
25 ms |
584 KB |
Output is correct |
29 |
Correct |
19 ms |
584 KB |
Output is correct |
30 |
Correct |
21 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
440 KB |
Output is correct |
3 |
Correct |
3 ms |
440 KB |
Output is correct |
4 |
Correct |
5 ms |
440 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
584 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
5 ms |
584 KB |
Output is correct |
9 |
Correct |
5 ms |
584 KB |
Output is correct |
10 |
Correct |
4 ms |
584 KB |
Output is correct |
11 |
Correct |
4 ms |
584 KB |
Output is correct |
12 |
Correct |
5 ms |
584 KB |
Output is correct |
13 |
Correct |
4 ms |
584 KB |
Output is correct |
14 |
Correct |
4 ms |
584 KB |
Output is correct |
15 |
Correct |
4 ms |
584 KB |
Output is correct |
16 |
Correct |
7 ms |
584 KB |
Output is correct |
17 |
Correct |
11 ms |
584 KB |
Output is correct |
18 |
Correct |
15 ms |
584 KB |
Output is correct |
19 |
Correct |
26 ms |
584 KB |
Output is correct |
20 |
Correct |
17 ms |
584 KB |
Output is correct |
21 |
Correct |
24 ms |
584 KB |
Output is correct |
22 |
Correct |
23 ms |
584 KB |
Output is correct |
23 |
Correct |
12 ms |
584 KB |
Output is correct |
24 |
Correct |
25 ms |
584 KB |
Output is correct |
25 |
Correct |
19 ms |
584 KB |
Output is correct |
26 |
Correct |
20 ms |
584 KB |
Output is correct |
27 |
Correct |
19 ms |
584 KB |
Output is correct |
28 |
Correct |
25 ms |
584 KB |
Output is correct |
29 |
Correct |
19 ms |
584 KB |
Output is correct |
30 |
Correct |
21 ms |
584 KB |
Output is correct |
31 |
Correct |
37 ms |
584 KB |
Output is correct |
32 |
Correct |
44 ms |
584 KB |
Output is correct |
33 |
Correct |
81 ms |
584 KB |
Output is correct |
34 |
Incorrect |
110 ms |
584 KB |
Wrong Answer [2] |
35 |
Halted |
0 ms |
0 KB |
- |