#include "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int a[5000];
map<pair<int,int>,int> marc;
int q(int ini, int fim)
{
if(!marc[{ini,fim}]) return marc[{ini,fim}] = query(ini,fim);
else return marc[{ini,fim}];
}
void solve(int N)
{
a[1] = 0;
a[2] = a[1] + q(1,2);
int menor = 2*N, maior = -2*N;
int minPos = 0, maxPos = 0;
for(int i = 2; i < N; i++)
{
int d12 = q(i-1,i);
int d23 = q(i,i+1);
int d13 = q(i-1,i+1);
int sign = (a[i] - a[i-1])/d12;
if(d13 == d12 + d23)
a[i+1] = a[i-1] + sign*(d13);
else
a[i+1] = a[i] - sign*(d23);
}
for(int i = 1; i <= N; i++)
{
if(a[i] < menor)
{
menor = a[i];
minPos = i;
}
if(a[i] > maior)
{
maior = a[i];
maxPos = i;
}
}
int dif = 1 - menor;
// cerr << menor << " " << maior << " Penis\n";
if(minPos < maxPos)
{
// cerr << "açldfjaklçsdfjlçaksfj";
for(int i = 1; i <= N; i++)
answer(i,a[i] + dif);
}
else
{
for(int i = 1; i <= N; i++)
{
// cerr << 1 << " " << N - a[i] - dif + 1 << "||\n";
// cerr << i << " " << N - (a[i] + dif) + 1 << "\n";
answer(i,N - (a[i] + dif) + 1);
}
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
4 ms |
444 KB |
Output is correct |
5 |
Correct |
4 ms |
448 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
452 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 ms |
444 KB |
Output is correct |
5 |
Correct |
4 ms |
448 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
452 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
428 KB |
Output is correct |
16 |
Correct |
8 ms |
444 KB |
Output is correct |
17 |
Correct |
15 ms |
440 KB |
Output is correct |
18 |
Correct |
31 ms |
592 KB |
Output is correct |
19 |
Correct |
30 ms |
508 KB |
Output is correct |
20 |
Correct |
32 ms |
492 KB |
Output is correct |
21 |
Correct |
35 ms |
736 KB |
Output is correct |
22 |
Correct |
30 ms |
584 KB |
Output is correct |
23 |
Correct |
31 ms |
336 KB |
Output is correct |
24 |
Correct |
35 ms |
584 KB |
Output is correct |
25 |
Correct |
33 ms |
1096 KB |
Output is correct |
26 |
Correct |
31 ms |
484 KB |
Output is correct |
27 |
Correct |
32 ms |
1504 KB |
Output is correct |
28 |
Correct |
34 ms |
584 KB |
Output is correct |
29 |
Correct |
39 ms |
1096 KB |
Output is correct |
30 |
Correct |
27 ms |
736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
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 |
4 ms |
444 KB |
Output is correct |
5 |
Correct |
4 ms |
448 KB |
Output is correct |
6 |
Correct |
4 ms |
336 KB |
Output is correct |
7 |
Correct |
3 ms |
336 KB |
Output is correct |
8 |
Correct |
3 ms |
592 KB |
Output is correct |
9 |
Correct |
4 ms |
336 KB |
Output is correct |
10 |
Correct |
4 ms |
336 KB |
Output is correct |
11 |
Correct |
4 ms |
452 KB |
Output is correct |
12 |
Correct |
4 ms |
336 KB |
Output is correct |
13 |
Correct |
4 ms |
336 KB |
Output is correct |
14 |
Correct |
4 ms |
336 KB |
Output is correct |
15 |
Correct |
4 ms |
428 KB |
Output is correct |
16 |
Correct |
8 ms |
444 KB |
Output is correct |
17 |
Correct |
15 ms |
440 KB |
Output is correct |
18 |
Correct |
31 ms |
592 KB |
Output is correct |
19 |
Correct |
30 ms |
508 KB |
Output is correct |
20 |
Correct |
32 ms |
492 KB |
Output is correct |
21 |
Correct |
35 ms |
736 KB |
Output is correct |
22 |
Correct |
30 ms |
584 KB |
Output is correct |
23 |
Correct |
31 ms |
336 KB |
Output is correct |
24 |
Correct |
35 ms |
584 KB |
Output is correct |
25 |
Correct |
33 ms |
1096 KB |
Output is correct |
26 |
Correct |
31 ms |
484 KB |
Output is correct |
27 |
Correct |
32 ms |
1504 KB |
Output is correct |
28 |
Correct |
34 ms |
584 KB |
Output is correct |
29 |
Correct |
39 ms |
1096 KB |
Output is correct |
30 |
Correct |
27 ms |
736 KB |
Output is correct |
31 |
Correct |
83 ms |
564 KB |
Output is correct |
32 |
Correct |
86 ms |
1268 KB |
Output is correct |
33 |
Correct |
159 ms |
1144 KB |
Output is correct |
34 |
Correct |
196 ms |
1500 KB |
Output is correct |
35 |
Correct |
167 ms |
1184 KB |
Output is correct |
36 |
Correct |
167 ms |
952 KB |
Output is correct |
37 |
Correct |
201 ms |
1312 KB |
Output is correct |
38 |
Correct |
196 ms |
1452 KB |
Output is correct |
39 |
Correct |
182 ms |
1752 KB |
Output is correct |
40 |
Correct |
199 ms |
1652 KB |
Output is correct |
41 |
Correct |
188 ms |
1776 KB |
Output is correct |
42 |
Correct |
215 ms |
1284 KB |
Output is correct |
43 |
Correct |
178 ms |
1648 KB |
Output is correct |
44 |
Correct |
195 ms |
1356 KB |
Output is correct |
45 |
Correct |
202 ms |
1508 KB |
Output is correct |
46 |
Correct |
186 ms |
1168 KB |
Output is correct |
47 |
Correct |
180 ms |
1684 KB |
Output is correct |
48 |
Correct |
194 ms |
1240 KB |
Output is correct |
49 |
Correct |
202 ms |
1508 KB |
Output is correct |
50 |
Correct |
186 ms |
1472 KB |
Output is correct |
51 |
Correct |
196 ms |
1484 KB |
Output is correct |
52 |
Correct |
182 ms |
1164 KB |
Output is correct |
53 |
Correct |
195 ms |
1256 KB |
Output is correct |
54 |
Correct |
196 ms |
1464 KB |
Output is correct |
55 |
Correct |
177 ms |
1320 KB |
Output is correct |
56 |
Correct |
197 ms |
1372 KB |
Output is correct |
57 |
Correct |
193 ms |
1064 KB |
Output is correct |
58 |
Correct |
188 ms |
1212 KB |
Output is correct |
59 |
Correct |
170 ms |
1236 KB |
Output is correct |
60 |
Correct |
193 ms |
1512 KB |
Output is correct |