#include "xylophone.h"
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#ifdef DEBUG
#include <time.h>
#endif
#define all(a) (a).begin(), (a).end()
#define rev(a) (a).rbegin(), (a).rend()
#define F first
#define S second
int recur_depth = 0;
#ifdef DEBUG
#define dbg(x) \
{ \
++recur_depth; \
auto x_ = x; \
--recur_depth; \
cerr << string(recur_depth, '\t') << "\e[91m" << __func__ << ":" \
<< __LINE__ << "\t" << #x << " = " << x_ << "\e[39m" << endl; \
}
#else
#define dbg(x)
#endif
using namespace std;
using namespace __gnu_pbds;
typedef pair<int, int> ii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> llll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vii;
typedef vector<vii> vvii;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pair<ll, ll>> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
template <class type1>
using ordered_set = tree<type1, null_type, less<type1>, rb_tree_tag,
tree_order_statistics_node_update>;
template <typename A, typename B>
ostream &operator<<(ostream &os, const pair<A, B> &p) {
return os << '(' << p.first << ", " << p.second << ')';
}
template <typename T_container, typename T = typename enable_if<
!is_same<T_container, string>::value,
typename T_container::value_type>::type>
ostream &operator<<(ostream &os, const T_container &v) {
os << '{';
string sep;
for (const T &x : v)
os << sep << x, sep = ", ";
return os << '}';
}
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
const ll INF = 1e9;
const ld EPS = 1e-9;
static int A[5000];
void solve(int N) {
vvi q(N + 1, vi(N + 1, -1));
int cnt = 0;
auto ask = [&](int s, int t) {
if (q[s][t] != -1)
return q[s][t];
cnt++;
return q[s][t] = query(s, t);
};
vi ans(N + 1, -1);
vi at(N + 1, -1);
int tot = ask(1, N);
int l = 2, r = N, pos_1 = 1;
while (l <= r) {
int mid = (l + r) / 2;
if (ask(mid, N) != tot)
r = mid - 1;
else {
pos_1 = mid;
l = mid + 1;
}
}
auto in_rng = [&](int x) { return 1 <= x && x <= N; };
auto fill_place = [&](int pos, int v) {
ans[v] = pos;
at[pos] = v;
};
fill_place(pos_1, 1);
at[pos_1] = 1;
if (pos_1 < N) {
fill_place(pos_1 + 1, 1 + ask(pos_1, pos_1 + 1));
for (int i = pos_1 + 2; i <= N; i++) {
int ab = ask(i - 2, i - 1), bc = ask(i - 1, i);
if (!in_rng(at[i - 1] + bc)) {
fill_place(i, at[i - 1] - bc);
continue;
}
if (!in_rng(at[i - 1] - bc)) {
fill_place(i, at[i - 1] + bc);
continue;
}
int ac = ask(i - 2, i);
if (ac == ab || ac == bc) {
if (at[i - 2] < at[i - 1])
fill_place(i, at[i - 1] - bc);
else
fill_place(i, at[i - 1] + bc);
} else {
if (at[i - 2] < at[i - 1])
fill_place(i, at[i - 1] + bc);
else
fill_place(i, at[i - 1] - bc);
}
}
}
if (pos_1 > 1) {
fill_place(pos_1 - 1, 1 + ask(pos_1 - 1, pos_1));
for (int i = pos_1 - 2; i >= 1; i--) {
int ab = ask(i, i + 1), bc = ask(i + 1, i + 2);
if (!in_rng(at[i + 1] + ab)) {
fill_place(i, at[i + 1] - ab);
continue;
}
if (!in_rng(at[i + 1] - ab)) {
fill_place(i, at[i + 1] + ab);
continue;
}
int ac = ask(i, i + 2);
if (ac == bc || ac == ab) {
if (at[i + 1] < at[i + 2])
fill_place(i, at[i + 1] + ab);
else
fill_place(i, at[i + 1] - ab);
} else {
if (at[i + 1] < at[i + 2])
fill_place(i, at[i + 1] - ab);
else
fill_place(i, at[i + 1] + ab);
}
}
}
for (int i = 1; i <= N; i++)
answer(i, at[i]);
}
Compilation message
xylophone.cpp:93:12: warning: 'A' defined but not used [-Wunused-variable]
93 | static int A[5000];
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
464 KB |
Output is correct |
17 |
Correct |
6 ms |
1104 KB |
Output is correct |
18 |
Correct |
11 ms |
2896 KB |
Output is correct |
19 |
Correct |
17 ms |
4176 KB |
Output is correct |
20 |
Correct |
17 ms |
4176 KB |
Output is correct |
21 |
Correct |
14 ms |
4240 KB |
Output is correct |
22 |
Correct |
11 ms |
4256 KB |
Output is correct |
23 |
Correct |
19 ms |
4244 KB |
Output is correct |
24 |
Correct |
10 ms |
4176 KB |
Output is correct |
25 |
Correct |
14 ms |
4264 KB |
Output is correct |
26 |
Correct |
8 ms |
4264 KB |
Output is correct |
27 |
Correct |
16 ms |
4240 KB |
Output is correct |
28 |
Correct |
15 ms |
4176 KB |
Output is correct |
29 |
Correct |
13 ms |
4260 KB |
Output is correct |
30 |
Correct |
13 ms |
4176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
2 ms |
336 KB |
Output is correct |
6 |
Correct |
2 ms |
336 KB |
Output is correct |
7 |
Correct |
2 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
2 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
336 KB |
Output is correct |
12 |
Correct |
2 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
3 ms |
464 KB |
Output is correct |
17 |
Correct |
6 ms |
1104 KB |
Output is correct |
18 |
Correct |
11 ms |
2896 KB |
Output is correct |
19 |
Correct |
17 ms |
4176 KB |
Output is correct |
20 |
Correct |
17 ms |
4176 KB |
Output is correct |
21 |
Correct |
14 ms |
4240 KB |
Output is correct |
22 |
Correct |
11 ms |
4256 KB |
Output is correct |
23 |
Correct |
19 ms |
4244 KB |
Output is correct |
24 |
Correct |
10 ms |
4176 KB |
Output is correct |
25 |
Correct |
14 ms |
4264 KB |
Output is correct |
26 |
Correct |
8 ms |
4264 KB |
Output is correct |
27 |
Correct |
16 ms |
4240 KB |
Output is correct |
28 |
Correct |
15 ms |
4176 KB |
Output is correct |
29 |
Correct |
13 ms |
4260 KB |
Output is correct |
30 |
Correct |
13 ms |
4176 KB |
Output is correct |
31 |
Correct |
35 ms |
18756 KB |
Output is correct |
32 |
Correct |
36 ms |
37740 KB |
Output is correct |
33 |
Correct |
85 ms |
74728 KB |
Output is correct |
34 |
Correct |
97 ms |
98240 KB |
Output is correct |
35 |
Correct |
58 ms |
98340 KB |
Output is correct |
36 |
Incorrect |
89 ms |
98248 KB |
Wrong Answer [2] |
37 |
Halted |
0 ms |
0 KB |
- |