#include <iostream>
#include "xylophone.h"
using namespace std;
#define nmax 5000
int v2[nmax], v3[nmax], semn[nmax], nr[nmax];
void solve( int n ) {
int i, x = 0, minn = 0, pozmin = 1, maxx = 0, pozmax = 1, t, aux;
for( i = 1; i < n; i++ )
v2[i] = query( i, i + 1 );
for( i = 1; i < n - 1; i++ )
v3[i] = query( i, i + 2 );
semn[1] = 1;
for( i = 1; i < n - 1; i++ ) {
if( v3[i] == v2[i] + v2[i + 1] )
semn[i+1] = semn[i];
else
semn[i+1] = - semn[i];
}
for( i = 2; i <= n; i++ ) {
x = x + v2[i-1] * semn[i-1];
//cout << x << " ";
if( x < minn ) {
minn = x;
pozmin = i;
} else if( x > maxx ) {
maxx = x;
pozmax = i;
}
}
//cout << "\n";
t = 1;
if( pozmin > pozmax ) {
t = -1;
aux = pozmin;
pozmin = pozmax;
pozmax = aux;
}
nr[pozmin] = 1;
for( i = pozmin + 1; i <= n; i++ )
nr[i] = nr[i-1] + v2[i-1] * t * semn[i-1];
for( i = pozmin - 1; i >= 1; i-- )
nr[i] = nr[i+1] - v2[i] * t * semn[i];
/*for( i = 1; i <= n; i++ )
cout << semn[i] << " ";
cout << "\n";
cout << pozmin << " " << pozmax;
cout << "\n";*/
for( i = 1; i <= n; i++ )
answer( i, nr[i] );
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
1 ms |
700 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
700 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
1 ms |
700 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
700 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
700 KB |
Output is correct |
17 |
Correct |
4 ms |
700 KB |
Output is correct |
18 |
Correct |
6 ms |
708 KB |
Output is correct |
19 |
Correct |
9 ms |
448 KB |
Output is correct |
20 |
Correct |
7 ms |
696 KB |
Output is correct |
21 |
Correct |
8 ms |
700 KB |
Output is correct |
22 |
Correct |
7 ms |
956 KB |
Output is correct |
23 |
Correct |
10 ms |
700 KB |
Output is correct |
24 |
Correct |
10 ms |
604 KB |
Output is correct |
25 |
Correct |
13 ms |
700 KB |
Output is correct |
26 |
Correct |
11 ms |
700 KB |
Output is correct |
27 |
Correct |
12 ms |
700 KB |
Output is correct |
28 |
Correct |
8 ms |
704 KB |
Output is correct |
29 |
Correct |
12 ms |
700 KB |
Output is correct |
30 |
Correct |
8 ms |
696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
448 KB |
Output is correct |
2 |
Correct |
0 ms |
436 KB |
Output is correct |
3 |
Correct |
1 ms |
608 KB |
Output is correct |
4 |
Correct |
1 ms |
444 KB |
Output is correct |
5 |
Correct |
1 ms |
452 KB |
Output is correct |
6 |
Correct |
1 ms |
700 KB |
Output is correct |
7 |
Correct |
1 ms |
444 KB |
Output is correct |
8 |
Correct |
1 ms |
448 KB |
Output is correct |
9 |
Correct |
1 ms |
448 KB |
Output is correct |
10 |
Correct |
1 ms |
444 KB |
Output is correct |
11 |
Correct |
1 ms |
436 KB |
Output is correct |
12 |
Correct |
1 ms |
700 KB |
Output is correct |
13 |
Correct |
1 ms |
440 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
440 KB |
Output is correct |
16 |
Correct |
2 ms |
700 KB |
Output is correct |
17 |
Correct |
4 ms |
700 KB |
Output is correct |
18 |
Correct |
6 ms |
708 KB |
Output is correct |
19 |
Correct |
9 ms |
448 KB |
Output is correct |
20 |
Correct |
7 ms |
696 KB |
Output is correct |
21 |
Correct |
8 ms |
700 KB |
Output is correct |
22 |
Correct |
7 ms |
956 KB |
Output is correct |
23 |
Correct |
10 ms |
700 KB |
Output is correct |
24 |
Correct |
10 ms |
604 KB |
Output is correct |
25 |
Correct |
13 ms |
700 KB |
Output is correct |
26 |
Correct |
11 ms |
700 KB |
Output is correct |
27 |
Correct |
12 ms |
700 KB |
Output is correct |
28 |
Correct |
8 ms |
704 KB |
Output is correct |
29 |
Correct |
12 ms |
700 KB |
Output is correct |
30 |
Correct |
8 ms |
696 KB |
Output is correct |
31 |
Correct |
20 ms |
960 KB |
Output is correct |
32 |
Correct |
29 ms |
948 KB |
Output is correct |
33 |
Correct |
39 ms |
704 KB |
Output is correct |
34 |
Correct |
58 ms |
704 KB |
Output is correct |
35 |
Correct |
45 ms |
700 KB |
Output is correct |
36 |
Correct |
45 ms |
1452 KB |
Output is correct |
37 |
Correct |
40 ms |
1224 KB |
Output is correct |
38 |
Correct |
53 ms |
700 KB |
Output is correct |
39 |
Correct |
41 ms |
1200 KB |
Output is correct |
40 |
Correct |
51 ms |
708 KB |
Output is correct |
41 |
Correct |
47 ms |
940 KB |
Output is correct |
42 |
Correct |
45 ms |
1204 KB |
Output is correct |
43 |
Correct |
47 ms |
976 KB |
Output is correct |
44 |
Correct |
42 ms |
1548 KB |
Output is correct |
45 |
Correct |
60 ms |
708 KB |
Output is correct |
46 |
Correct |
52 ms |
944 KB |
Output is correct |
47 |
Correct |
47 ms |
1216 KB |
Output is correct |
48 |
Correct |
47 ms |
956 KB |
Output is correct |
49 |
Correct |
53 ms |
712 KB |
Output is correct |
50 |
Correct |
46 ms |
708 KB |
Output is correct |
51 |
Correct |
48 ms |
1204 KB |
Output is correct |
52 |
Correct |
58 ms |
944 KB |
Output is correct |
53 |
Correct |
49 ms |
1212 KB |
Output is correct |
54 |
Correct |
51 ms |
960 KB |
Output is correct |
55 |
Correct |
57 ms |
1200 KB |
Output is correct |
56 |
Correct |
37 ms |
956 KB |
Output is correct |
57 |
Correct |
45 ms |
948 KB |
Output is correct |
58 |
Correct |
54 ms |
1200 KB |
Output is correct |
59 |
Correct |
45 ms |
964 KB |
Output is correct |
60 |
Correct |
45 ms |
692 KB |
Output is correct |