#include <cstdio>
#include <cstdlib>
#include "xylophone.h"
#include <bits/stdc++.h>
int doi[10005],trei[10005],v[10005],fr[10005],ok,val1;
int max1(int a,int b)
{
if (a>b)
{
return a;
}
return b;
}
int min1(int a,int b)
{
if (a<b)
{
return a;
}
return b;
}
int valoare(int a,int b,int c)
{
int maxim=max1(a,max1(b,c));
int minim=min1(a,min1(b,c));
return maxim-minim;
}
void solve(int n) {
int i,j;
for (i=1;i<=n-1;i++)
{
doi[i]=query(i,i+1);
}
for (i=1;i<=n-2;i++)
{
trei[i]=query(i,i+2);
}
for (i=2;i<=n;i++)
{
/// presupun ca pe pozitia i am N
for (j=1;j<=n;j++)
{
v[j]=0;
fr[j]=0;
}
v[i]=n;
v[i-1]=n-doi[i-1];
ok=1;
for (j=i-2;j>=1;j--)
{
if (v[j+1]-doi[j]>=1)
{
val1=v[j+1]-doi[j];
if (valoare(val1,v[j+1],v[j+2])==trei[j])
{
v[j]=val1;
continue;
}
}
if (v[j+1]+doi[j]<=n)
{
val1=v[j+1]+doi[j];
if (valoare(val1,v[j+1],v[j+2])==trei[j])
{
v[j]=val1;
continue;
}
}
ok=0;
break;
}
if (ok==0)
{
continue;
}
if (i<n)
{
v[i+1]=n-doi[i];
for (j=i+2;j<=n;j++)
{
if (v[j-1]-doi[j-1]>=1)
{
val1=v[j-1]-doi[j-1];
if (valoare(val1,v[j-1],v[j-2])==trei[j-2])
{
v[j]=val1;
continue;
}
}
if (v[j-1]+doi[j-1]<=n)
{
val1=v[j-1]+doi[j-1];
if (valoare(val1,v[j-1],v[j-2])==trei[j-2])
{
v[j]=val1;
continue;
}
}
ok=0;
break;
}
}
if (ok==0)
{
continue;
}
int poz=n+1;
for (j=1;j<=n;j++)
{
if (v[j]==1)
{
poz=j;
}
if (fr[v[j]]!=0)
{
ok=0;
break;
}
fr[v[j]]=1;
}
if (ok==0)
{
continue;
}
if (poz>i)
{
continue;
}
for (j=1;j<=n;j++)
{
answer(j,v[j]);
}
break;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
3 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
300 KB |
Output is correct |
13 |
Correct |
3 ms |
304 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
3 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
300 KB |
Output is correct |
13 |
Correct |
3 ms |
304 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
292 KB |
Output is correct |
16 |
Correct |
4 ms |
308 KB |
Output is correct |
17 |
Correct |
5 ms |
308 KB |
Output is correct |
18 |
Correct |
20 ms |
284 KB |
Output is correct |
19 |
Correct |
18 ms |
304 KB |
Output is correct |
20 |
Correct |
11 ms |
328 KB |
Output is correct |
21 |
Correct |
18 ms |
304 KB |
Output is correct |
22 |
Correct |
17 ms |
200 KB |
Output is correct |
23 |
Correct |
21 ms |
308 KB |
Output is correct |
24 |
Correct |
23 ms |
200 KB |
Output is correct |
25 |
Correct |
23 ms |
292 KB |
Output is correct |
26 |
Correct |
21 ms |
200 KB |
Output is correct |
27 |
Correct |
26 ms |
300 KB |
Output is correct |
28 |
Correct |
14 ms |
304 KB |
Output is correct |
29 |
Correct |
26 ms |
292 KB |
Output is correct |
30 |
Correct |
26 ms |
300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
2 ms |
200 KB |
Output is correct |
5 |
Correct |
3 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
3 ms |
328 KB |
Output is correct |
8 |
Correct |
2 ms |
200 KB |
Output is correct |
9 |
Correct |
3 ms |
200 KB |
Output is correct |
10 |
Correct |
3 ms |
304 KB |
Output is correct |
11 |
Correct |
3 ms |
200 KB |
Output is correct |
12 |
Correct |
3 ms |
300 KB |
Output is correct |
13 |
Correct |
3 ms |
304 KB |
Output is correct |
14 |
Correct |
4 ms |
200 KB |
Output is correct |
15 |
Correct |
2 ms |
292 KB |
Output is correct |
16 |
Correct |
4 ms |
308 KB |
Output is correct |
17 |
Correct |
5 ms |
308 KB |
Output is correct |
18 |
Correct |
20 ms |
284 KB |
Output is correct |
19 |
Correct |
18 ms |
304 KB |
Output is correct |
20 |
Correct |
11 ms |
328 KB |
Output is correct |
21 |
Correct |
18 ms |
304 KB |
Output is correct |
22 |
Correct |
17 ms |
200 KB |
Output is correct |
23 |
Correct |
21 ms |
308 KB |
Output is correct |
24 |
Correct |
23 ms |
200 KB |
Output is correct |
25 |
Correct |
23 ms |
292 KB |
Output is correct |
26 |
Correct |
21 ms |
200 KB |
Output is correct |
27 |
Correct |
26 ms |
300 KB |
Output is correct |
28 |
Correct |
14 ms |
304 KB |
Output is correct |
29 |
Correct |
26 ms |
292 KB |
Output is correct |
30 |
Correct |
26 ms |
300 KB |
Output is correct |
31 |
Correct |
57 ms |
292 KB |
Output is correct |
32 |
Correct |
69 ms |
304 KB |
Output is correct |
33 |
Correct |
133 ms |
304 KB |
Output is correct |
34 |
Correct |
90 ms |
316 KB |
Output is correct |
35 |
Correct |
102 ms |
436 KB |
Output is correct |
36 |
Correct |
226 ms |
420 KB |
Output is correct |
37 |
Correct |
158 ms |
364 KB |
Output is correct |
38 |
Correct |
87 ms |
412 KB |
Output is correct |
39 |
Correct |
116 ms |
296 KB |
Output is correct |
40 |
Correct |
113 ms |
548 KB |
Output is correct |
41 |
Correct |
95 ms |
296 KB |
Output is correct |
42 |
Correct |
263 ms |
320 KB |
Output is correct |
43 |
Correct |
155 ms |
372 KB |
Output is correct |
44 |
Correct |
111 ms |
320 KB |
Output is correct |
45 |
Correct |
91 ms |
320 KB |
Output is correct |
46 |
Correct |
105 ms |
296 KB |
Output is correct |
47 |
Correct |
126 ms |
300 KB |
Output is correct |
48 |
Correct |
99 ms |
580 KB |
Output is correct |
49 |
Correct |
114 ms |
464 KB |
Output is correct |
50 |
Correct |
103 ms |
308 KB |
Output is correct |
51 |
Correct |
119 ms |
316 KB |
Output is correct |
52 |
Correct |
125 ms |
304 KB |
Output is correct |
53 |
Correct |
122 ms |
292 KB |
Output is correct |
54 |
Correct |
96 ms |
324 KB |
Output is correct |
55 |
Correct |
121 ms |
336 KB |
Output is correct |
56 |
Correct |
114 ms |
280 KB |
Output is correct |
57 |
Correct |
116 ms |
368 KB |
Output is correct |
58 |
Correct |
148 ms |
320 KB |
Output is correct |
59 |
Correct |
100 ms |
324 KB |
Output is correct |
60 |
Correct |
98 ms |
316 KB |
Output is correct |