#include <bits/stdc++.h>
#include <xylophone.h>
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
int n;
int okay(vector<int> q)
{
int pos1 = 0, posn = 0;
vector<int> cnt(n + 1);
for (int i = 1; i <= n; i++)
{
if (q[i] < 1 || q[i] > n) return 0;
cnt[q[i]]++;
if (cnt[q[i]] == 2) return 0;
if (q[i] == 1) pos1 = i;
if (q[i] == n) posn = i;
}
return pos1 < posn;
}
void solve(int n0)
{
n = n0;
vector<int> a(n), b(n);
for (int i = 1; i + 1 <= n; i++)
{
a[i] = query(i, i + 1);
}
for (int i = 1; i + 2 <= n; i++)
{
b[i] = query(i, i + 2);
}
vector<int> dir(n);
dir[1] = 1;
for (int i = 1; i + 2 <= n; i++)
{
if (b[i] == a[i] + a[i + 1]) dir[i + 1] = dir[i];
else dir[i + 1] = dir[i] * (-1);
}
vector<vector<int> > ans;
for (int i = 1; i <= n; i++)
{
vector<int> q(n + 1);
q[1] = i;
q[2] = dir[1] * a[1] + q[1];
for (int j = 3; j <= n; j++)
{
q[j] = q[j - 1] + dir[j - 1] * a[j - 1];
}
if (okay(q)) ans.push_back(q);
}
for (int i = 1; i < n; i++) dir[i] *= -1;
for (int i = 1; i <= n; i++)
{
vector<int> q(n + 1);
q[1] = i;
q[2] = dir[1] * a[1] + q[1];
for (int j = 3; j <= n; j++)
{
q[j] = q[j - 1] + dir[j - 1] * a[j - 1];
}
if (okay(q)) ans.push_back(q);
}
for (auto e : ans)
{
for (int i = 1; i <= n; i++)
{
answer(i, e[i]);
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
3 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
3 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
11 ms |
384 KB |
Output is correct |
18 |
Correct |
37 ms |
376 KB |
Output is correct |
19 |
Correct |
30 ms |
376 KB |
Output is correct |
20 |
Correct |
25 ms |
384 KB |
Output is correct |
21 |
Correct |
25 ms |
384 KB |
Output is correct |
22 |
Correct |
22 ms |
376 KB |
Output is correct |
23 |
Correct |
47 ms |
384 KB |
Output is correct |
24 |
Correct |
25 ms |
376 KB |
Output is correct |
25 |
Correct |
21 ms |
376 KB |
Output is correct |
26 |
Correct |
28 ms |
376 KB |
Output is correct |
27 |
Correct |
28 ms |
504 KB |
Output is correct |
28 |
Correct |
43 ms |
384 KB |
Output is correct |
29 |
Correct |
35 ms |
384 KB |
Output is correct |
30 |
Correct |
35 ms |
400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
3 ms |
256 KB |
Output is correct |
5 |
Correct |
3 ms |
256 KB |
Output is correct |
6 |
Correct |
4 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
372 KB |
Output is correct |
10 |
Correct |
3 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
256 KB |
Output is correct |
16 |
Correct |
5 ms |
256 KB |
Output is correct |
17 |
Correct |
11 ms |
384 KB |
Output is correct |
18 |
Correct |
37 ms |
376 KB |
Output is correct |
19 |
Correct |
30 ms |
376 KB |
Output is correct |
20 |
Correct |
25 ms |
384 KB |
Output is correct |
21 |
Correct |
25 ms |
384 KB |
Output is correct |
22 |
Correct |
22 ms |
376 KB |
Output is correct |
23 |
Correct |
47 ms |
384 KB |
Output is correct |
24 |
Correct |
25 ms |
376 KB |
Output is correct |
25 |
Correct |
21 ms |
376 KB |
Output is correct |
26 |
Correct |
28 ms |
376 KB |
Output is correct |
27 |
Correct |
28 ms |
504 KB |
Output is correct |
28 |
Correct |
43 ms |
384 KB |
Output is correct |
29 |
Correct |
35 ms |
384 KB |
Output is correct |
30 |
Correct |
35 ms |
400 KB |
Output is correct |
31 |
Correct |
95 ms |
384 KB |
Output is correct |
32 |
Correct |
156 ms |
384 KB |
Output is correct |
33 |
Correct |
266 ms |
508 KB |
Output is correct |
34 |
Correct |
336 ms |
504 KB |
Output is correct |
35 |
Correct |
323 ms |
504 KB |
Output is correct |
36 |
Correct |
408 ms |
508 KB |
Output is correct |
37 |
Correct |
408 ms |
504 KB |
Output is correct |
38 |
Correct |
328 ms |
540 KB |
Output is correct |
39 |
Correct |
334 ms |
540 KB |
Output is correct |
40 |
Correct |
361 ms |
536 KB |
Output is correct |
41 |
Correct |
286 ms |
504 KB |
Output is correct |
42 |
Correct |
413 ms |
536 KB |
Output is correct |
43 |
Correct |
413 ms |
504 KB |
Output is correct |
44 |
Correct |
320 ms |
504 KB |
Output is correct |
45 |
Correct |
320 ms |
616 KB |
Output is correct |
46 |
Correct |
286 ms |
504 KB |
Output is correct |
47 |
Correct |
270 ms |
504 KB |
Output is correct |
48 |
Correct |
324 ms |
504 KB |
Output is correct |
49 |
Correct |
324 ms |
504 KB |
Output is correct |
50 |
Correct |
321 ms |
484 KB |
Output is correct |
51 |
Correct |
328 ms |
504 KB |
Output is correct |
52 |
Correct |
364 ms |
536 KB |
Output is correct |
53 |
Correct |
337 ms |
484 KB |
Output is correct |
54 |
Correct |
317 ms |
504 KB |
Output is correct |
55 |
Correct |
329 ms |
408 KB |
Output is correct |
56 |
Correct |
306 ms |
536 KB |
Output is correct |
57 |
Correct |
322 ms |
536 KB |
Output is correct |
58 |
Correct |
327 ms |
504 KB |
Output is correct |
59 |
Correct |
277 ms |
540 KB |
Output is correct |
60 |
Correct |
282 ms |
504 KB |
Output is correct |