#include <bits/stdc++.h>
#include "xylophone.h"
using namespace std;
#define MAXN 5010
int razlike[MAXN];
int ans1[MAXN],ans2[MAXN];
void solve(int N)
{
for (int i=1;i<N;i++) razlike[i]=query(i,i+1);
ans1[1]=0,ans2[1]=0;ans1[2]=razlike[1],ans2[2]=razlike[1]*(-1);
for (int i=3;i<=N;i++)
{
int sol=query(i-2,i);
if (sol==razlike[i-2]+razlike[i-1])
{
if (ans1[i-2]>ans1[i-1]) ans1[i]=ans1[i-1]-razlike[i-1];
else ans1[i]=ans1[i-1]+razlike[i-1];
if (ans2[i-2]>ans2[i-1]) ans2[i]=ans2[i-1]-razlike[i-1];
else ans2[i]=ans2[i-1]+razlike[i-1];
}
else
{
if (ans1[i-2]>ans1[i-1]) ans1[i]=ans1[i-1]+razlike[i-1];
else ans1[i]=ans1[i-1]-razlike[i-1];
if (ans2[i-2]>ans2[i-1]) ans2[i]=ans2[i-1]+razlike[i-1];
else ans2[i]=ans2[i-1]-razlike[i-1];
}
}
int mini1=INT_MAX,mini2=INT_MAX;
for (int i=1;i<=N;i++) mini1=min(mini1,ans1[i]);
for (int i=1;i<=N;i++) mini2=min(mini2,ans2[i]);
int dodajemo1=1-mini1,dodajemo2=1-mini2;
for (int i=1;i<=N;i++) ans1[i]+=dodajemo1;
for (int i=1;i<=N;i++) ans2[i]+=dodajemo2;
int maksi1=-INT_MAX,maksi2=-INT_MAX;
for (int i=1;i<=N;i++) maksi1=max(maksi1,ans1[i]);
for (int i=1;i<=N;i++) maksi2=max(maksi2,ans2[i]);
if (maksi1==N)
{
int poz1,pozN;
for (int i=1;i<=N;i++)
{
if (ans1[i]==1) poz1=i;
if (ans1[i]==N) pozN=i;
}
if (poz1>pozN)
{
for (int i=1;i<=N;i++) ans1[i]=N-ans1[i]+1;
}
for (int i=1;i<=N;i++) answer(i,ans1[i]);
}
else
{
int poz1,pozN;
for (int i=1;i<=N;i++)
{
if (ans2[i]==1) poz1=i;
if (ans2[i]==N) pozN=i;
}
if (poz1>pozN)
{
for (int i=1;i<=N;i++) ans2[i]=N-ans2[i]+1;
}
for (int i=1;i<=N;i++) answer(i,ans2[i]);
}
};
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:64:9: warning: 'pozN' may be used uninitialized in this function [-Wmaybe-uninitialized]
64 | if (poz1>pozN)
| ^~
xylophone.cpp:64:9: warning: 'poz1' may be used uninitialized in this function [-Wmaybe-uninitialized]
xylophone.cpp:50:9: warning: 'pozN' may be used uninitialized in this function [-Wmaybe-uninitialized]
50 | if (poz1>pozN)
| ^~
xylophone.cpp:50:9: warning: 'poz1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 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 |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
444 KB |
Output is correct |
18 |
Correct |
7 ms |
444 KB |
Output is correct |
19 |
Correct |
10 ms |
600 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
8 ms |
344 KB |
Output is correct |
24 |
Correct |
9 ms |
344 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
448 KB |
Output is correct |
27 |
Correct |
9 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
856 KB |
Output is correct |
29 |
Correct |
9 ms |
344 KB |
Output is correct |
30 |
Correct |
9 ms |
452 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 |
1 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 |
344 KB |
Output is correct |
17 |
Correct |
5 ms |
444 KB |
Output is correct |
18 |
Correct |
7 ms |
444 KB |
Output is correct |
19 |
Correct |
10 ms |
600 KB |
Output is correct |
20 |
Correct |
9 ms |
344 KB |
Output is correct |
21 |
Correct |
12 ms |
344 KB |
Output is correct |
22 |
Correct |
9 ms |
344 KB |
Output is correct |
23 |
Correct |
8 ms |
344 KB |
Output is correct |
24 |
Correct |
9 ms |
344 KB |
Output is correct |
25 |
Correct |
9 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
448 KB |
Output is correct |
27 |
Correct |
9 ms |
344 KB |
Output is correct |
28 |
Correct |
15 ms |
856 KB |
Output is correct |
29 |
Correct |
9 ms |
344 KB |
Output is correct |
30 |
Correct |
9 ms |
452 KB |
Output is correct |
31 |
Correct |
26 ms |
856 KB |
Output is correct |
32 |
Correct |
32 ms |
344 KB |
Output is correct |
33 |
Correct |
39 ms |
708 KB |
Output is correct |
34 |
Correct |
47 ms |
700 KB |
Output is correct |
35 |
Correct |
51 ms |
600 KB |
Output is correct |
36 |
Correct |
67 ms |
464 KB |
Output is correct |
37 |
Correct |
69 ms |
448 KB |
Output is correct |
38 |
Correct |
58 ms |
848 KB |
Output is correct |
39 |
Correct |
64 ms |
696 KB |
Output is correct |
40 |
Correct |
65 ms |
704 KB |
Output is correct |
41 |
Correct |
55 ms |
680 KB |
Output is correct |
42 |
Correct |
55 ms |
436 KB |
Output is correct |
43 |
Correct |
53 ms |
600 KB |
Output is correct |
44 |
Correct |
49 ms |
696 KB |
Output is correct |
45 |
Correct |
55 ms |
696 KB |
Output is correct |
46 |
Correct |
43 ms |
464 KB |
Output is correct |
47 |
Correct |
60 ms |
592 KB |
Output is correct |
48 |
Correct |
57 ms |
692 KB |
Output is correct |
49 |
Correct |
59 ms |
696 KB |
Output is correct |
50 |
Correct |
42 ms |
692 KB |
Output is correct |
51 |
Correct |
44 ms |
956 KB |
Output is correct |
52 |
Correct |
68 ms |
704 KB |
Output is correct |
53 |
Correct |
41 ms |
596 KB |
Output is correct |
54 |
Correct |
52 ms |
692 KB |
Output is correct |
55 |
Correct |
59 ms |
696 KB |
Output is correct |
56 |
Correct |
62 ms |
704 KB |
Output is correct |
57 |
Correct |
60 ms |
600 KB |
Output is correct |
58 |
Correct |
52 ms |
596 KB |
Output is correct |
59 |
Correct |
58 ms |
696 KB |
Output is correct |
60 |
Correct |
56 ms |
676 KB |
Output is correct |