#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
bool Check(int a, int b, int c, int i) {
if (a == b || b == c || a == c) {return false;}
if (a > b && b > c) {
return query(i + 1, i + 3) == a - c;
}
if (a > c && c > b) {
return query(i + 1, i + 3) == a - b;
}
if (c > a && a > b) {
return query(i + 1, i + 3) == c - b;
}
if (c > b && b > a) {
return query(i + 1, i + 3) == c - a;
}
if (b > a && a > c) {
return query(i + 1, i + 3) == b - c;
}
if (b > c && c > a) {
return query(i + 1, i + 3) == b - a;
}
}
int GetRight(int n, int a, int b, int x, int i) {
int c1 = b + x, c2 = b - x;
if (c1 > n) {return c2;}
if (c2 < 1) {return c1;}
if (Check(a, b, c1, i)) {
return c1;
}
return c2;
}
int GetLeft(int n, int a, int b, int x, int i) {
int c1 = a + x, c2 = a - x;
if (c1 > n) {return c2;}
if (c2 < 1) {return c1;}
if (Check(c1, a, b, i)) {
return c1;
}
return c2;
}
void solve(int n) {
int pos = n - 1;
while (query(1, pos) == n - 1) {
--pos;
}
vector <int> num(n);
num[pos] = n;
if (pos + 1 < n) {
int x = query(pos + 1, pos + 2);
num[pos + 1] = n - x;
}
vector <vector<int>> cand1(n), cand2(n);
for (int i = pos + 2; i < n; ++i) {
int x = query(pos + 2, pos + 3);
num[i] = GetRight(n, num[i - 2], num[i - 1], x, i - 2);
}
if (pos != 0) {
int x = query(pos, pos + 1);
num[pos - 1] = n - x;
}
for (int i = pos - 2; i >= 0; --i) {
int x = query(i + 1, i + 2);
num[i] = GetLeft(n, num[i + 1], num[i + 2], x, i);
}
for(int i = 0; i < n; ++i) {
answer(i + 1, num[i]);
}
}
Compilation message
xylophone.cpp: In function 'bool Check(int, int, int, int)':
xylophone.cpp:26:1: warning: control reaches end of non-void function [-Wreturn-type]
26 | }
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Wrong Answer [7] |
4 |
Halted |
0 ms |
0 KB |
- |