#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define per(i, a, b) for (int i = b - 1; i >= (a); --i)
#define trav(a, x) for (auto &a : x)
#define all(x) x.begin(), x.end()
#define sz(x) x.size()
#define pb push_back
#define umap unordered_map
#define uset unordered_set
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef long long ll;
const int INF = 1000000007;
void solve(int n) {
int diff[5001], ans[5001], dir[5001];
rep(i, 0, n - 1) diff[i] = query(i + 1, i + 2);
rep(i, 1, n - 1) {
int val = query(i, i + 2);
dir[i] = val != diff[i - 1] + diff[i];
}
rep(i, 0, n) {
bitset<5001> vis;
ans[0] = i + 1;
ans[1] = ans[0] + diff[0];
if (ans[1] < 1 || n < ans[1]) continue;
vis[i + 1] = vis[ans[1]] = 1;
int cd = 1;
bool works = 1, lo = i==0, rev = 0;
rep(i, 1, n - 1) {
if (ans[i] == n && !lo) rev = 1;
if (ans[i] == 1) lo = 1;
cd ^= dir[i];
ans[i + 1] = ans[i] + (cd ? diff[i] : -diff[i]);
if (ans[i + 1] < 1 || n < ans[i + 1] || vis[ans[i + 1]]) {
works = 0;
break;
}
vis[ans[i + 1]] = 1;
}
if (ans[n - 1] < 1 || n < ans[n - 1]) works = 0;
if (works) {
if (rev) rep(i, 0, n) ans[i] = n - ans[i] + 1;
break;
}
}
rep(i, 0, n) answer(i + 1, ans[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
200 KB |
Output is correct |
5 |
Correct |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
3 ms |
432 KB |
Output is correct |
8 |
Correct |
4 ms |
200 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
4 ms |
200 KB |
Output is correct |
11 |
Correct |
5 ms |
300 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
4 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
304 KB |
Output is correct |
15 |
Correct |
3 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
200 KB |
Output is correct |
5 |
Correct |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
3 ms |
432 KB |
Output is correct |
8 |
Correct |
4 ms |
200 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
4 ms |
200 KB |
Output is correct |
11 |
Correct |
5 ms |
300 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
4 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
304 KB |
Output is correct |
15 |
Correct |
3 ms |
200 KB |
Output is correct |
16 |
Correct |
7 ms |
308 KB |
Output is correct |
17 |
Correct |
12 ms |
300 KB |
Output is correct |
18 |
Correct |
8 ms |
296 KB |
Output is correct |
19 |
Correct |
25 ms |
296 KB |
Output is correct |
20 |
Correct |
24 ms |
200 KB |
Output is correct |
21 |
Correct |
27 ms |
312 KB |
Output is correct |
22 |
Correct |
25 ms |
428 KB |
Output is correct |
23 |
Correct |
27 ms |
320 KB |
Output is correct |
24 |
Correct |
22 ms |
284 KB |
Output is correct |
25 |
Correct |
21 ms |
304 KB |
Output is correct |
26 |
Correct |
21 ms |
308 KB |
Output is correct |
27 |
Correct |
17 ms |
288 KB |
Output is correct |
28 |
Correct |
24 ms |
296 KB |
Output is correct |
29 |
Correct |
18 ms |
296 KB |
Output is correct |
30 |
Correct |
27 ms |
304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
3 ms |
200 KB |
Output is correct |
5 |
Correct |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
3 ms |
200 KB |
Output is correct |
7 |
Correct |
3 ms |
432 KB |
Output is correct |
8 |
Correct |
4 ms |
200 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
4 ms |
200 KB |
Output is correct |
11 |
Correct |
5 ms |
300 KB |
Output is correct |
12 |
Correct |
3 ms |
200 KB |
Output is correct |
13 |
Correct |
4 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
304 KB |
Output is correct |
15 |
Correct |
3 ms |
200 KB |
Output is correct |
16 |
Correct |
7 ms |
308 KB |
Output is correct |
17 |
Correct |
12 ms |
300 KB |
Output is correct |
18 |
Correct |
8 ms |
296 KB |
Output is correct |
19 |
Correct |
25 ms |
296 KB |
Output is correct |
20 |
Correct |
24 ms |
200 KB |
Output is correct |
21 |
Correct |
27 ms |
312 KB |
Output is correct |
22 |
Correct |
25 ms |
428 KB |
Output is correct |
23 |
Correct |
27 ms |
320 KB |
Output is correct |
24 |
Correct |
22 ms |
284 KB |
Output is correct |
25 |
Correct |
21 ms |
304 KB |
Output is correct |
26 |
Correct |
21 ms |
308 KB |
Output is correct |
27 |
Correct |
17 ms |
288 KB |
Output is correct |
28 |
Correct |
24 ms |
296 KB |
Output is correct |
29 |
Correct |
18 ms |
296 KB |
Output is correct |
30 |
Correct |
27 ms |
304 KB |
Output is correct |
31 |
Correct |
43 ms |
304 KB |
Output is correct |
32 |
Correct |
77 ms |
320 KB |
Output is correct |
33 |
Correct |
108 ms |
416 KB |
Output is correct |
34 |
Correct |
136 ms |
296 KB |
Output is correct |
35 |
Correct |
100 ms |
440 KB |
Output is correct |
36 |
Correct |
53 ms |
308 KB |
Output is correct |
37 |
Correct |
170 ms |
324 KB |
Output is correct |
38 |
Correct |
113 ms |
432 KB |
Output is correct |
39 |
Correct |
112 ms |
332 KB |
Output is correct |
40 |
Correct |
105 ms |
308 KB |
Output is correct |
41 |
Correct |
130 ms |
296 KB |
Output is correct |
42 |
Correct |
93 ms |
308 KB |
Output is correct |
43 |
Correct |
134 ms |
304 KB |
Output is correct |
44 |
Correct |
90 ms |
292 KB |
Output is correct |
45 |
Correct |
116 ms |
432 KB |
Output is correct |
46 |
Correct |
97 ms |
312 KB |
Output is correct |
47 |
Correct |
97 ms |
424 KB |
Output is correct |
48 |
Correct |
122 ms |
420 KB |
Output is correct |
49 |
Correct |
96 ms |
320 KB |
Output is correct |
50 |
Correct |
150 ms |
320 KB |
Output is correct |
51 |
Correct |
112 ms |
352 KB |
Output is correct |
52 |
Correct |
84 ms |
296 KB |
Output is correct |
53 |
Correct |
104 ms |
304 KB |
Output is correct |
54 |
Correct |
123 ms |
300 KB |
Output is correct |
55 |
Correct |
94 ms |
324 KB |
Output is correct |
56 |
Correct |
87 ms |
424 KB |
Output is correct |
57 |
Correct |
102 ms |
316 KB |
Output is correct |
58 |
Correct |
110 ms |
452 KB |
Output is correct |
59 |
Correct |
124 ms |
320 KB |
Output is correct |
60 |
Correct |
108 ms |
448 KB |
Output is correct |