#include<bits/stdc++.h>
#include "xylophone.h"
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<int>
#define vii vector<vi>
#define pint pair<int,int>
#define vpint vector<pint>
#define aint(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 1e4+8;
const ll buff = 1e5+1;
int a[N],dist[N][2];
int pos[5008];
bool check(int n) {
fill(pos + 1, pos + n + 1, 0);
for (int i = 1; i <= n; ++i)
if (a[i] <= 0 || a[i] > n) return 0;
else pos[a[i]] = i;
for (int i = 1; i <= n; ++i) if (!pos[i]) return 0;
return pos[1] < pos[n];
}
void solve(int n){
for(int i = 2; i <= n; i++){
if(i > 1) dist[i][0] = query(i-1,i);
if(i > 2) dist[i][1] = query(i-2,i);
}
for(int x = 1; x <= n; x++){
a[1] = x;
a[2] = x+dist[2][0];
for(int i = 3; i <= n; i++){
if(a[i-2] > a[i-1]){
if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0];
else a[i] = a[i-1]+dist[i][0];
}
else{
if (a[i-1]-a[i-2]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0];
else a[i] = a[i-1]-dist[i][0];
}
}
if(check(n)) break;
a[1] = x;
a[2] = x-dist[2][0];
for(int i = 3; i <= n; i++){
if(a[i-2] > a[i-1]){
if (a[i-2]-a[i-1]+dist[i][0] == dist[i][1]) a[i] = a[i-1]-dist[i][0];
else a[i] = a[i-1]+dist[i][0];
}
else{
if (a[i-1]-a[i-2]+dist[i][0] == dist[i][1]) a[i] = a[i-1]+dist[i][0];
else a[i] = a[i-1]-dist[i][0];
}
}
if(check(n)) break;
}
for(int i = 1; i <= n; i++) answer(i,a[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
444 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
11 ms |
448 KB |
Output is correct |
20 |
Correct |
8 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
696 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
14 ms |
344 KB |
Output is correct |
25 |
Correct |
11 ms |
600 KB |
Output is correct |
26 |
Correct |
14 ms |
440 KB |
Output is correct |
27 |
Correct |
10 ms |
596 KB |
Output is correct |
28 |
Correct |
10 ms |
344 KB |
Output is correct |
29 |
Correct |
11 ms |
440 KB |
Output is correct |
30 |
Correct |
10 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
2 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
2 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
2 ms |
444 KB |
Output is correct |
17 |
Correct |
5 ms |
344 KB |
Output is correct |
18 |
Correct |
8 ms |
344 KB |
Output is correct |
19 |
Correct |
11 ms |
448 KB |
Output is correct |
20 |
Correct |
8 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
696 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
9 ms |
344 KB |
Output is correct |
24 |
Correct |
14 ms |
344 KB |
Output is correct |
25 |
Correct |
11 ms |
600 KB |
Output is correct |
26 |
Correct |
14 ms |
440 KB |
Output is correct |
27 |
Correct |
10 ms |
596 KB |
Output is correct |
28 |
Correct |
10 ms |
344 KB |
Output is correct |
29 |
Correct |
11 ms |
440 KB |
Output is correct |
30 |
Correct |
10 ms |
600 KB |
Output is correct |
31 |
Correct |
24 ms |
688 KB |
Output is correct |
32 |
Correct |
57 ms |
684 KB |
Output is correct |
33 |
Correct |
55 ms |
696 KB |
Output is correct |
34 |
Correct |
95 ms |
684 KB |
Output is correct |
35 |
Correct |
95 ms |
592 KB |
Output is correct |
36 |
Correct |
41 ms |
596 KB |
Output is correct |
37 |
Correct |
83 ms |
600 KB |
Output is correct |
38 |
Correct |
39 ms |
688 KB |
Output is correct |
39 |
Correct |
56 ms |
448 KB |
Output is correct |
40 |
Correct |
82 ms |
848 KB |
Output is correct |
41 |
Correct |
98 ms |
600 KB |
Output is correct |
42 |
Correct |
58 ms |
696 KB |
Output is correct |
43 |
Correct |
90 ms |
340 KB |
Output is correct |
44 |
Correct |
56 ms |
680 KB |
Output is correct |
45 |
Correct |
85 ms |
704 KB |
Output is correct |
46 |
Correct |
120 ms |
1104 KB |
Output is correct |
47 |
Correct |
111 ms |
444 KB |
Output is correct |
48 |
Correct |
57 ms |
696 KB |
Output is correct |
49 |
Correct |
115 ms |
692 KB |
Output is correct |
50 |
Correct |
119 ms |
592 KB |
Output is correct |
51 |
Correct |
84 ms |
928 KB |
Output is correct |
52 |
Correct |
61 ms |
704 KB |
Output is correct |
53 |
Correct |
111 ms |
592 KB |
Output is correct |
54 |
Correct |
92 ms |
600 KB |
Output is correct |
55 |
Correct |
108 ms |
692 KB |
Output is correct |
56 |
Correct |
104 ms |
448 KB |
Output is correct |
57 |
Correct |
98 ms |
344 KB |
Output is correct |
58 |
Correct |
135 ms |
592 KB |
Output is correct |
59 |
Correct |
78 ms |
696 KB |
Output is correct |
60 |
Correct |
81 ms |
464 KB |
Output is correct |