#include <bits/stdc++.h>
using namespace std;
int a[5005];
int b[5005];
int diff1[5005];
int diff2[5005];
bool same[5005];
bool bigger[5005];
int query(int s,int t);
void answer(int i,int v);
void solve(int n)
{
if(n==2)
{
answer(1,1);
answer(2,2);
return;
}
for(int i=1; i<n; i++)
diff1[i]=query(i,i+1);
for(int i=1; i<n-1; i++)
diff2[i]=query(i,i+2);
for(int i=1; i<n-1; i++)
{
if(diff2[i]==diff1[i]+diff1[i+1])
same[i]=1;
else
same[i]=0;
}
int sign=1;
a[1]=0;
for(int i=1; i<n; i++)
{
a[i+1]=a[i]+sign*diff1[i];
if(i+1<n && same[i]==0)
sign*=-1;
}
sign=-1;
b[1]=0;
for(int i=1; i<n; i++)
{
b[i+1]=b[i]+sign*diff1[i];
if(i+1<n && same[i]==0)
sign*=-1;
}
/*
for(int i=1; i<=n; i++)
cout<<A[i]<<" ";
cout<<"\n";
for(int i=1; i<=n; i++)
cout<<B[i]<<" ";
cout<<"\n";
*/
int minA=n;
for(int i=1; i<=n; i++)
minA=min(minA,a[i]);
int minB=n;
for(int i=1; i<=n; i++)
minB=min(minB,b[i]);
int pminA,pminB;
for(int i=1; i<=n; i++)
{
if(a[i]==minA)
pminA=i;
if(b[i]==minB)
pminB=i;
}
if(pminB<pminA)
{
for(int i=1; i<=n; i++)
swap(a[i],b[i]);
swap(minA,minB);
}
for(int i=1; i<=n; i++)
answer(i,a[i]-minA+1);
}
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:84:5: warning: 'pminB' may be used uninitialized in this function [-Wmaybe-uninitialized]
84 | if(pminB<pminA)
| ^~
xylophone.cpp:84:5: warning: 'pminA' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
696 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
688 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
696 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
696 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
688 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
696 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
16 |
Correct |
2 ms |
692 KB |
Output is correct |
17 |
Correct |
5 ms |
1464 KB |
Output is correct |
18 |
Correct |
8 ms |
952 KB |
Output is correct |
19 |
Correct |
11 ms |
1208 KB |
Output is correct |
20 |
Correct |
8 ms |
700 KB |
Output is correct |
21 |
Correct |
8 ms |
700 KB |
Output is correct |
22 |
Correct |
9 ms |
696 KB |
Output is correct |
23 |
Correct |
8 ms |
696 KB |
Output is correct |
24 |
Correct |
9 ms |
436 KB |
Output is correct |
25 |
Correct |
10 ms |
696 KB |
Output is correct |
26 |
Correct |
11 ms |
696 KB |
Output is correct |
27 |
Correct |
13 ms |
696 KB |
Output is correct |
28 |
Correct |
8 ms |
952 KB |
Output is correct |
29 |
Correct |
7 ms |
960 KB |
Output is correct |
30 |
Correct |
10 ms |
952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
440 KB |
Output is correct |
3 |
Correct |
1 ms |
444 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
696 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
688 KB |
Output is correct |
9 |
Correct |
1 ms |
440 KB |
Output is correct |
10 |
Correct |
1 ms |
696 KB |
Output is correct |
11 |
Correct |
1 ms |
440 KB |
Output is correct |
12 |
Correct |
1 ms |
600 KB |
Output is correct |
13 |
Correct |
1 ms |
436 KB |
Output is correct |
14 |
Correct |
1 ms |
436 KB |
Output is correct |
15 |
Correct |
1 ms |
444 KB |
Output is correct |
16 |
Correct |
2 ms |
692 KB |
Output is correct |
17 |
Correct |
5 ms |
1464 KB |
Output is correct |
18 |
Correct |
8 ms |
952 KB |
Output is correct |
19 |
Correct |
11 ms |
1208 KB |
Output is correct |
20 |
Correct |
8 ms |
700 KB |
Output is correct |
21 |
Correct |
8 ms |
700 KB |
Output is correct |
22 |
Correct |
9 ms |
696 KB |
Output is correct |
23 |
Correct |
8 ms |
696 KB |
Output is correct |
24 |
Correct |
9 ms |
436 KB |
Output is correct |
25 |
Correct |
10 ms |
696 KB |
Output is correct |
26 |
Correct |
11 ms |
696 KB |
Output is correct |
27 |
Correct |
13 ms |
696 KB |
Output is correct |
28 |
Correct |
8 ms |
952 KB |
Output is correct |
29 |
Correct |
7 ms |
960 KB |
Output is correct |
30 |
Correct |
10 ms |
952 KB |
Output is correct |
31 |
Correct |
18 ms |
952 KB |
Output is correct |
32 |
Correct |
28 ms |
1200 KB |
Output is correct |
33 |
Correct |
52 ms |
952 KB |
Output is correct |
34 |
Correct |
53 ms |
696 KB |
Output is correct |
35 |
Correct |
53 ms |
1200 KB |
Output is correct |
36 |
Correct |
65 ms |
744 KB |
Output is correct |
37 |
Correct |
59 ms |
944 KB |
Output is correct |
38 |
Correct |
55 ms |
748 KB |
Output is correct |
39 |
Correct |
49 ms |
956 KB |
Output is correct |
40 |
Correct |
56 ms |
952 KB |
Output is correct |
41 |
Correct |
50 ms |
1212 KB |
Output is correct |
42 |
Correct |
40 ms |
1216 KB |
Output is correct |
43 |
Correct |
58 ms |
700 KB |
Output is correct |
44 |
Correct |
54 ms |
700 KB |
Output is correct |
45 |
Correct |
53 ms |
948 KB |
Output is correct |
46 |
Correct |
55 ms |
1212 KB |
Output is correct |
47 |
Correct |
64 ms |
708 KB |
Output is correct |
48 |
Correct |
63 ms |
696 KB |
Output is correct |
49 |
Correct |
47 ms |
1204 KB |
Output is correct |
50 |
Correct |
49 ms |
756 KB |
Output is correct |
51 |
Correct |
52 ms |
936 KB |
Output is correct |
52 |
Correct |
53 ms |
960 KB |
Output is correct |
53 |
Correct |
48 ms |
956 KB |
Output is correct |
54 |
Correct |
61 ms |
952 KB |
Output is correct |
55 |
Correct |
48 ms |
1252 KB |
Output is correct |
56 |
Correct |
62 ms |
1196 KB |
Output is correct |
57 |
Correct |
53 ms |
704 KB |
Output is correct |
58 |
Correct |
56 ms |
1212 KB |
Output is correct |
59 |
Correct |
40 ms |
1216 KB |
Output is correct |
60 |
Correct |
56 ms |
1196 KB |
Output is correct |