#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
vector<int> to_perm(vector<int> &raw) {
int mini = 1e9;
for (int x: raw)
mini = min(mini, x);
vector<int> ans;
for (int x: raw)
ans.push_back(x - mini + 1);
return ans;
}
void solve(int n) {
vector<int> delta;
for (int i = 1; i < n; ++i)
delta.push_back(query(i, i + 1));
vector<bool> sign{false};
for (int i = 1; i < n - 1; ++i) {
int t = query(i, i + 2);
if (delta[i-1] + delta[i] == t) sign.push_back(sign.back());
else sign.push_back(!sign.back());
}
vector<int> raw{0};
for (int i = 0; i < n-1; ++i)
raw.push_back(raw.back() + delta[i]*(sign[i] ? 1 : -1));
auto ps = to_perm(raw);
for (int &x: raw) x = -x;
auto qs = to_perm(raw);
bool ansp = true;
for (int i = 0; i < n; ++i)
if (ps[i] == 1) break;
else if (ps[i] == n) {
ansp = false;
break;
}
if (ansp) {
for (int i = 0; i < n; ++i)
answer(i + 1, ps[i]);
return;
}
for (int i = 0; i < n; ++i)
answer(i + 1, qs[i]);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
436 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
440 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
436 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
440 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
336 KB |
Output is correct |
17 |
Correct |
15 ms |
436 KB |
Output is correct |
18 |
Correct |
24 ms |
592 KB |
Output is correct |
19 |
Correct |
36 ms |
448 KB |
Output is correct |
20 |
Correct |
28 ms |
336 KB |
Output is correct |
21 |
Correct |
26 ms |
336 KB |
Output is correct |
22 |
Correct |
28 ms |
444 KB |
Output is correct |
23 |
Correct |
24 ms |
436 KB |
Output is correct |
24 |
Correct |
28 ms |
584 KB |
Output is correct |
25 |
Correct |
34 ms |
436 KB |
Output is correct |
26 |
Correct |
25 ms |
336 KB |
Output is correct |
27 |
Correct |
29 ms |
336 KB |
Output is correct |
28 |
Correct |
29 ms |
336 KB |
Output is correct |
29 |
Correct |
35 ms |
592 KB |
Output is correct |
30 |
Correct |
28 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
3 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
336 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
4 ms |
592 KB |
Output is correct |
8 |
Correct |
3 ms |
436 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
440 KB |
Output is correct |
11 |
Correct |
4 ms |
336 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
3 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
440 KB |
Output is correct |
15 |
Correct |
4 ms |
336 KB |
Output is correct |
16 |
Correct |
5 ms |
336 KB |
Output is correct |
17 |
Correct |
15 ms |
436 KB |
Output is correct |
18 |
Correct |
24 ms |
592 KB |
Output is correct |
19 |
Correct |
36 ms |
448 KB |
Output is correct |
20 |
Correct |
28 ms |
336 KB |
Output is correct |
21 |
Correct |
26 ms |
336 KB |
Output is correct |
22 |
Correct |
28 ms |
444 KB |
Output is correct |
23 |
Correct |
24 ms |
436 KB |
Output is correct |
24 |
Correct |
28 ms |
584 KB |
Output is correct |
25 |
Correct |
34 ms |
436 KB |
Output is correct |
26 |
Correct |
25 ms |
336 KB |
Output is correct |
27 |
Correct |
29 ms |
336 KB |
Output is correct |
28 |
Correct |
29 ms |
336 KB |
Output is correct |
29 |
Correct |
35 ms |
592 KB |
Output is correct |
30 |
Correct |
28 ms |
336 KB |
Output is correct |
31 |
Correct |
60 ms |
848 KB |
Output is correct |
32 |
Correct |
105 ms |
584 KB |
Output is correct |
33 |
Correct |
163 ms |
616 KB |
Output is correct |
34 |
Correct |
179 ms |
952 KB |
Output is correct |
35 |
Correct |
186 ms |
584 KB |
Output is correct |
36 |
Correct |
182 ms |
692 KB |
Output is correct |
37 |
Correct |
170 ms |
480 KB |
Output is correct |
38 |
Correct |
181 ms |
584 KB |
Output is correct |
39 |
Correct |
167 ms |
712 KB |
Output is correct |
40 |
Correct |
190 ms |
840 KB |
Output is correct |
41 |
Correct |
181 ms |
600 KB |
Output is correct |
42 |
Correct |
179 ms |
864 KB |
Output is correct |
43 |
Correct |
154 ms |
692 KB |
Output is correct |
44 |
Correct |
194 ms |
584 KB |
Output is correct |
45 |
Correct |
183 ms |
716 KB |
Output is correct |
46 |
Correct |
177 ms |
700 KB |
Output is correct |
47 |
Correct |
172 ms |
840 KB |
Output is correct |
48 |
Correct |
169 ms |
592 KB |
Output is correct |
49 |
Correct |
181 ms |
336 KB |
Output is correct |
50 |
Correct |
190 ms |
336 KB |
Output is correct |
51 |
Correct |
177 ms |
712 KB |
Output is correct |
52 |
Correct |
194 ms |
696 KB |
Output is correct |
53 |
Correct |
172 ms |
960 KB |
Output is correct |
54 |
Correct |
170 ms |
704 KB |
Output is correct |
55 |
Correct |
174 ms |
712 KB |
Output is correct |
56 |
Correct |
161 ms |
716 KB |
Output is correct |
57 |
Correct |
176 ms |
696 KB |
Output is correct |
58 |
Correct |
186 ms |
600 KB |
Output is correct |
59 |
Correct |
176 ms |
696 KB |
Output is correct |
60 |
Correct |
170 ms |
696 KB |
Output is correct |