#include <bits/stdc++.h>
#include "xylophone.h"
#define MAX_N 5000
using namespace std;
int A[MAX_N + 1];
#ifdef local
int query(int s, int t)
{
int mn = 5000;
int mx = 1;
for(int i = s; i <= t; i ++)
{
mn = min(mn, A[i]);
mx = max(mx, A[i]);
}
return mx - mn;
}
#endif // local
int n;
int cautBin()
{
int i = 0;
int pas = 1 << 12;
while(pas != 0)
{
if(i + pas < n && query(1, i + pas) != n - 1)
i += pas;
pas >>= 1;
}
return i + 1;
}
int v[MAX_N + 1];
int diff[MAX_N + 1];
int ap[MAX_N + 1];
void baga(int st, int dr, int pas)
{
for(int i = st; i != dr + pas; i += pas)
{
int sign = 0;
int x = (i - pas < i ? query(i - pas, i) : query(i, i - pas));
if(v[i - pas] + x >= n || ap[v[i - pas] + x] == 1)
sign = -1;
else
if(v[i - pas] - x < 1 || ap[v[i - pas] - x] == 1)
sign = 1;
else
{
int y = (i - 2*pas < i ? query(i - 2*pas, i) : query(i, i - 2*pas));
if(y == diff[i - pas])
sign = (v[i - 2*pas] < v[i - pas] ? -1 : 1);
else
if(y == x + diff[i - pas])
sign = (v[i - pas] < v[i - 2*pas] ? -1 : 1);
else if(y == x)
sign = (v[i - pas] > v[i - 2*pas] ? -1 : 1);
}
diff[i] = x;
v[i] = v[i - pas] + x * sign;
ap[v[i]] = 1;
}
}
#ifdef local
void answer(int i, int nr)
{
if(nr != A[i])
{
cout << "PE POZ " << i << " ESTE " << A[i] << " TIU ZCICI " << nr << "\n";
exit(0);
}
// cout << " PE " << i << " " << nr << " == " << A[i] << "\n";
}
#endif // local
void solve(int N)
{
n = N;
int poz = cautBin();
v[poz] = n;
ap[v[poz]] = 1;
if(poz + 1 <= n)
{
v[poz + 1] = n - query(poz, poz + 1);
diff[poz + 1] = v[poz] - v[poz + 1];
ap[v[poz + 1]] = 1;
if(poz + 2 <= n)
baga(poz + 2, n, 1);
}
if(poz - 1 >= 1)
{
v[poz - 1] = n - query(poz - 1, poz);
diff[poz - 1] = v[poz] - v[poz - 1];
ap[v[poz - 1]] = 1;
if(poz - 2 >= 1)
baga(poz - 2, 1, -1);
}
for(int i = 1; i <= n; i ++)
answer(i, v[i]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
408 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
408 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
384 KB |
Output is correct |
19 |
Correct |
16 ms |
392 KB |
Output is correct |
20 |
Correct |
16 ms |
384 KB |
Output is correct |
21 |
Correct |
15 ms |
392 KB |
Output is correct |
22 |
Correct |
16 ms |
384 KB |
Output is correct |
23 |
Correct |
14 ms |
384 KB |
Output is correct |
24 |
Correct |
15 ms |
384 KB |
Output is correct |
25 |
Correct |
14 ms |
384 KB |
Output is correct |
26 |
Correct |
11 ms |
408 KB |
Output is correct |
27 |
Correct |
16 ms |
384 KB |
Output is correct |
28 |
Correct |
19 ms |
384 KB |
Output is correct |
29 |
Correct |
19 ms |
384 KB |
Output is correct |
30 |
Correct |
15 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
6 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
408 KB |
Output is correct |
6 |
Correct |
6 ms |
384 KB |
Output is correct |
7 |
Correct |
6 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
6 ms |
384 KB |
Output is correct |
11 |
Correct |
6 ms |
384 KB |
Output is correct |
12 |
Correct |
6 ms |
256 KB |
Output is correct |
13 |
Correct |
6 ms |
256 KB |
Output is correct |
14 |
Correct |
6 ms |
384 KB |
Output is correct |
15 |
Correct |
6 ms |
256 KB |
Output is correct |
16 |
Correct |
6 ms |
384 KB |
Output is correct |
17 |
Correct |
10 ms |
384 KB |
Output is correct |
18 |
Correct |
14 ms |
384 KB |
Output is correct |
19 |
Correct |
16 ms |
392 KB |
Output is correct |
20 |
Correct |
16 ms |
384 KB |
Output is correct |
21 |
Correct |
15 ms |
392 KB |
Output is correct |
22 |
Correct |
16 ms |
384 KB |
Output is correct |
23 |
Correct |
14 ms |
384 KB |
Output is correct |
24 |
Correct |
15 ms |
384 KB |
Output is correct |
25 |
Correct |
14 ms |
384 KB |
Output is correct |
26 |
Correct |
11 ms |
408 KB |
Output is correct |
27 |
Correct |
16 ms |
384 KB |
Output is correct |
28 |
Correct |
19 ms |
384 KB |
Output is correct |
29 |
Correct |
19 ms |
384 KB |
Output is correct |
30 |
Correct |
15 ms |
384 KB |
Output is correct |
31 |
Correct |
25 ms |
384 KB |
Output is correct |
32 |
Correct |
39 ms |
384 KB |
Output is correct |
33 |
Correct |
50 ms |
384 KB |
Output is correct |
34 |
Correct |
59 ms |
384 KB |
Output is correct |
35 |
Correct |
54 ms |
384 KB |
Output is correct |
36 |
Correct |
48 ms |
384 KB |
Output is correct |
37 |
Correct |
48 ms |
392 KB |
Output is correct |
38 |
Correct |
40 ms |
384 KB |
Output is correct |
39 |
Correct |
60 ms |
384 KB |
Output is correct |
40 |
Correct |
55 ms |
384 KB |
Output is correct |
41 |
Correct |
61 ms |
384 KB |
Output is correct |
42 |
Correct |
48 ms |
384 KB |
Output is correct |
43 |
Correct |
46 ms |
404 KB |
Output is correct |
44 |
Correct |
47 ms |
540 KB |
Output is correct |
45 |
Correct |
63 ms |
480 KB |
Output is correct |
46 |
Correct |
57 ms |
408 KB |
Output is correct |
47 |
Correct |
50 ms |
380 KB |
Output is correct |
48 |
Correct |
70 ms |
384 KB |
Output is correct |
49 |
Correct |
62 ms |
540 KB |
Output is correct |
50 |
Correct |
56 ms |
384 KB |
Output is correct |
51 |
Correct |
61 ms |
384 KB |
Output is correct |
52 |
Correct |
57 ms |
428 KB |
Output is correct |
53 |
Correct |
62 ms |
384 KB |
Output is correct |
54 |
Correct |
63 ms |
384 KB |
Output is correct |
55 |
Correct |
63 ms |
512 KB |
Output is correct |
56 |
Correct |
58 ms |
384 KB |
Output is correct |
57 |
Correct |
59 ms |
504 KB |
Output is correct |
58 |
Correct |
62 ms |
384 KB |
Output is correct |
59 |
Correct |
63 ms |
384 KB |
Output is correct |
60 |
Correct |
58 ms |
384 KB |
Output is correct |