#include "xylophone.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
//static int A[5000];
ll i,du[5050],ti[5050],d[5050],a[5050],I,J,mi;
void solve(int N) {
for(i=1;i<N;i++)du[i]=query(i,i+1);
for(i=1;i<(N-1);i++)ti[i]=query(i,i+2);
d[2]=du[1];
for(i=3;i<=N;i++)
{
if(ti[i-2]==(du[i-2]+du[i-1]))
{
//cout<<"A"<<"\n";
if(d[i-1]>0)d[i]=du[i-1];
if(d[i-1]<0)d[i]=-du[i-1];
}
else
{
if(d[i-1]>0)d[i]=-du[i-1];
if(d[i-1]<0)d[i]=du[i-1];
}
}
mi=1e18;
for(i=1;i<=N;i++)a[i]=a[i-1]+d[i];
for(i=1;i<=N;i++)mi=min(mi,a[i]);
for(i=1;i<=N;i++)a[i]-=(mi-1);
for(i=1;i<=N;i++)if(a[i]==1)I=i;
for(i=1;i<=N;i++)if(a[i]==N)J=i;
if(I>J)
{
d[2]=-du[1];
for(i=3;i<=N;i++)
{
if(ti[i-2]==(du[i-2]+du[i-1]))
{
if(d[i-1]>0)d[i]=du[i-1];
if(d[i-1]<0)d[i]=-du[i-1];
}
else
{
if(d[i-1]>0)d[i]=-du[i-1];
if(d[i-1]<0)d[i]=du[i-1];
}
}
mi=1e18;
for(i=1;i<=N;i++)a[i]=a[i-1]+d[i];
for(i=1;i<=N;i++)mi=min(mi,a[i]);
for(i=1;i<=N;i++)a[i]-=(mi-1);
}
for(i=1;i<=N;i++)answer(i,a[i]);
//for(i=1;i<=N;i++)cout<<i<<" "<<a[i]<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
18 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
252 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
420 KB |
Output is correct |
12 |
Correct |
4 ms |
248 KB |
Output is correct |
13 |
Correct |
4 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
4 ms |
248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
18 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
252 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
420 KB |
Output is correct |
12 |
Correct |
4 ms |
248 KB |
Output is correct |
13 |
Correct |
4 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
4 ms |
248 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
248 KB |
Output is correct |
18 |
Correct |
14 ms |
248 KB |
Output is correct |
19 |
Correct |
9 ms |
324 KB |
Output is correct |
20 |
Correct |
15 ms |
248 KB |
Output is correct |
21 |
Correct |
19 ms |
248 KB |
Output is correct |
22 |
Correct |
20 ms |
324 KB |
Output is correct |
23 |
Correct |
19 ms |
408 KB |
Output is correct |
24 |
Correct |
23 ms |
316 KB |
Output is correct |
25 |
Correct |
25 ms |
332 KB |
Output is correct |
26 |
Correct |
8 ms |
396 KB |
Output is correct |
27 |
Correct |
20 ms |
376 KB |
Output is correct |
28 |
Correct |
17 ms |
248 KB |
Output is correct |
29 |
Correct |
21 ms |
376 KB |
Output is correct |
30 |
Correct |
18 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Output is correct |
2 |
Correct |
1 ms |
248 KB |
Output is correct |
3 |
Correct |
2 ms |
400 KB |
Output is correct |
4 |
Correct |
4 ms |
248 KB |
Output is correct |
5 |
Correct |
4 ms |
248 KB |
Output is correct |
6 |
Correct |
4 ms |
376 KB |
Output is correct |
7 |
Correct |
18 ms |
248 KB |
Output is correct |
8 |
Correct |
3 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
252 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
420 KB |
Output is correct |
12 |
Correct |
4 ms |
248 KB |
Output is correct |
13 |
Correct |
4 ms |
248 KB |
Output is correct |
14 |
Correct |
3 ms |
248 KB |
Output is correct |
15 |
Correct |
4 ms |
248 KB |
Output is correct |
16 |
Correct |
5 ms |
376 KB |
Output is correct |
17 |
Correct |
10 ms |
248 KB |
Output is correct |
18 |
Correct |
14 ms |
248 KB |
Output is correct |
19 |
Correct |
9 ms |
324 KB |
Output is correct |
20 |
Correct |
15 ms |
248 KB |
Output is correct |
21 |
Correct |
19 ms |
248 KB |
Output is correct |
22 |
Correct |
20 ms |
324 KB |
Output is correct |
23 |
Correct |
19 ms |
408 KB |
Output is correct |
24 |
Correct |
23 ms |
316 KB |
Output is correct |
25 |
Correct |
25 ms |
332 KB |
Output is correct |
26 |
Correct |
8 ms |
396 KB |
Output is correct |
27 |
Correct |
20 ms |
376 KB |
Output is correct |
28 |
Correct |
17 ms |
248 KB |
Output is correct |
29 |
Correct |
21 ms |
376 KB |
Output is correct |
30 |
Correct |
18 ms |
376 KB |
Output is correct |
31 |
Correct |
43 ms |
376 KB |
Output is correct |
32 |
Correct |
56 ms |
380 KB |
Output is correct |
33 |
Correct |
76 ms |
376 KB |
Output is correct |
34 |
Correct |
92 ms |
396 KB |
Output is correct |
35 |
Correct |
85 ms |
384 KB |
Output is correct |
36 |
Correct |
58 ms |
504 KB |
Output is correct |
37 |
Correct |
88 ms |
376 KB |
Output is correct |
38 |
Correct |
33 ms |
452 KB |
Output is correct |
39 |
Correct |
38 ms |
452 KB |
Output is correct |
40 |
Correct |
81 ms |
508 KB |
Output is correct |
41 |
Correct |
122 ms |
472 KB |
Output is correct |
42 |
Correct |
57 ms |
524 KB |
Output is correct |
43 |
Correct |
75 ms |
456 KB |
Output is correct |
44 |
Correct |
85 ms |
356 KB |
Output is correct |
45 |
Correct |
34 ms |
444 KB |
Output is correct |
46 |
Correct |
46 ms |
476 KB |
Output is correct |
47 |
Correct |
34 ms |
440 KB |
Output is correct |
48 |
Correct |
82 ms |
460 KB |
Output is correct |
49 |
Correct |
83 ms |
416 KB |
Output is correct |
50 |
Correct |
52 ms |
548 KB |
Output is correct |
51 |
Correct |
71 ms |
424 KB |
Output is correct |
52 |
Correct |
89 ms |
476 KB |
Output is correct |
53 |
Correct |
50 ms |
376 KB |
Output is correct |
54 |
Correct |
97 ms |
460 KB |
Output is correct |
55 |
Correct |
100 ms |
376 KB |
Output is correct |
56 |
Correct |
106 ms |
436 KB |
Output is correct |
57 |
Correct |
91 ms |
376 KB |
Output is correct |
58 |
Correct |
90 ms |
380 KB |
Output is correct |
59 |
Correct |
89 ms |
376 KB |
Output is correct |
60 |
Correct |
78 ms |
420 KB |
Output is correct |