#include <iostream>
using namespace std;
//#define unx xun
#ifndef unx
#include "xylophone.h"
#endif
int a[5010], b[5010], sign[5010], x[5010], y[5010];
int asked[5010][5010];
#ifdef unx
int n;
int query(int s,int t){
int mx=0, mn=5000;
for(int i=s;i<=t;++i) mx=mx>a[i]?mx:a[i], mn=mn>a[i]?a[i]:mn;
return mx-mn;
}
void answer(int i,int val){
cout<<val<<" ";
}
#endif
int ask(int s,int t){
if(asked[s][t]) return asked[s][t]; else return asked[s][t]=query(s,t);
}
void solve(int n){
for(int i=2;i<=n;++i) x[i-1]=ask(i-1,i);
for(int i=2;i<n;++i) y[i-1]=ask(i-1,i+1);
if(x[1]+x[2]==y[1])
sign[1]=sign[2]=1;
else
sign[1]=1, sign[2]=-1;
for(int i=3;i<n;++i){
if(x[i-1] + x[i] == y[i-1])
sign[i]=sign[i-1];
else{
sign[i]=-sign[i-1];
}
}
a[1]=0;
int dif1=0, dif2=0;
for(int i=1;i<n;++i){
dif1=min(dif1,a[i+1]=a[i] + (sign[i]>0 ? x[i] : -x[i]));
dif2=min(dif2,b[i+1]=b[i] + (sign[i]>0 ? -x[i] : x[i]));
}
int o1,z1, o2,z2;
for(int i=1;i<=n;++i){
a[i]-=dif1-1, b[i]-=dif2-1;
if(a[i]==1) o1=i; if(a[i]==n) z1=i;
if(b[i]==1) o2=i; if(b[i]==n) z2=i;
}
if(o1<z1)
for(int i=1;i<=n;++i) answer(i,a[i]);
else
for(int i=1;i<=n;++i) answer(i,b[i]);
}
#ifdef unx
main(){
freopen("xylophone.inp","r",stdin);
cin>>n;
for(int i=1;i<=n;++i) cin>>a[i];
//cout<<solve(n)<<"\n";
solve(n);
}
#endif
Compilation message
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:57:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(a[i]==1) o1=i; if(a[i]==n) z1=i;
^~
xylophone.cpp:57:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(a[i]==1) o1=i; if(a[i]==n) z1=i;
^~
xylophone.cpp:58:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(b[i]==1) o2=i; if(b[i]==n) z2=i;
^~
xylophone.cpp:58:27: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(b[i]==1) o2=i; if(b[i]==n) z2=i;
^~
xylophone.cpp:54:16: warning: variable 'o2' set but not used [-Wunused-but-set-variable]
int o1,z1, o2,z2;
^~
xylophone.cpp:54:19: warning: variable 'z2' set but not used [-Wunused-but-set-variable]
int o1,z1, o2,z2;
^~
xylophone.cpp:61:5: warning: 'z1' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(o1<z1)
^~
xylophone.cpp:61:5: warning: 'o1' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
768 KB |
Output is correct |
6 |
Correct |
7 ms |
768 KB |
Output is correct |
7 |
Correct |
6 ms |
768 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
788 KB |
Output is correct |
10 |
Correct |
6 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
7 ms |
768 KB |
Output is correct |
14 |
Correct |
7 ms |
768 KB |
Output is correct |
15 |
Correct |
7 ms |
768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
768 KB |
Output is correct |
6 |
Correct |
7 ms |
768 KB |
Output is correct |
7 |
Correct |
6 ms |
768 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
788 KB |
Output is correct |
10 |
Correct |
6 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
7 ms |
768 KB |
Output is correct |
14 |
Correct |
7 ms |
768 KB |
Output is correct |
15 |
Correct |
7 ms |
768 KB |
Output is correct |
16 |
Correct |
9 ms |
1280 KB |
Output is correct |
17 |
Correct |
14 ms |
2304 KB |
Output is correct |
18 |
Correct |
24 ms |
3704 KB |
Output is correct |
19 |
Correct |
24 ms |
4472 KB |
Output is correct |
20 |
Correct |
26 ms |
4344 KB |
Output is correct |
21 |
Correct |
26 ms |
4352 KB |
Output is correct |
22 |
Correct |
25 ms |
4344 KB |
Output is correct |
23 |
Correct |
24 ms |
4472 KB |
Output is correct |
24 |
Correct |
29 ms |
4472 KB |
Output is correct |
25 |
Correct |
24 ms |
4412 KB |
Output is correct |
26 |
Correct |
27 ms |
4344 KB |
Output is correct |
27 |
Correct |
25 ms |
4400 KB |
Output is correct |
28 |
Correct |
26 ms |
4344 KB |
Output is correct |
29 |
Correct |
29 ms |
4344 KB |
Output is correct |
30 |
Correct |
24 ms |
4352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
512 KB |
Output is correct |
4 |
Correct |
7 ms |
768 KB |
Output is correct |
5 |
Correct |
7 ms |
768 KB |
Output is correct |
6 |
Correct |
7 ms |
768 KB |
Output is correct |
7 |
Correct |
6 ms |
768 KB |
Output is correct |
8 |
Correct |
6 ms |
768 KB |
Output is correct |
9 |
Correct |
7 ms |
788 KB |
Output is correct |
10 |
Correct |
6 ms |
768 KB |
Output is correct |
11 |
Correct |
7 ms |
768 KB |
Output is correct |
12 |
Correct |
7 ms |
768 KB |
Output is correct |
13 |
Correct |
7 ms |
768 KB |
Output is correct |
14 |
Correct |
7 ms |
768 KB |
Output is correct |
15 |
Correct |
7 ms |
768 KB |
Output is correct |
16 |
Correct |
9 ms |
1280 KB |
Output is correct |
17 |
Correct |
14 ms |
2304 KB |
Output is correct |
18 |
Correct |
24 ms |
3704 KB |
Output is correct |
19 |
Correct |
24 ms |
4472 KB |
Output is correct |
20 |
Correct |
26 ms |
4344 KB |
Output is correct |
21 |
Correct |
26 ms |
4352 KB |
Output is correct |
22 |
Correct |
25 ms |
4344 KB |
Output is correct |
23 |
Correct |
24 ms |
4472 KB |
Output is correct |
24 |
Correct |
29 ms |
4472 KB |
Output is correct |
25 |
Correct |
24 ms |
4412 KB |
Output is correct |
26 |
Correct |
27 ms |
4344 KB |
Output is correct |
27 |
Correct |
25 ms |
4400 KB |
Output is correct |
28 |
Correct |
26 ms |
4344 KB |
Output is correct |
29 |
Correct |
29 ms |
4344 KB |
Output is correct |
30 |
Correct |
24 ms |
4352 KB |
Output is correct |
31 |
Correct |
50 ms |
9128 KB |
Output is correct |
32 |
Correct |
67 ms |
12920 KB |
Output is correct |
33 |
Correct |
93 ms |
18040 KB |
Output is correct |
34 |
Correct |
107 ms |
20600 KB |
Output is correct |
35 |
Correct |
97 ms |
20600 KB |
Output is correct |
36 |
Correct |
97 ms |
20600 KB |
Output is correct |
37 |
Correct |
105 ms |
20600 KB |
Output is correct |
38 |
Correct |
113 ms |
20704 KB |
Output is correct |
39 |
Correct |
109 ms |
20600 KB |
Output is correct |
40 |
Correct |
96 ms |
20600 KB |
Output is correct |
41 |
Correct |
114 ms |
20752 KB |
Output is correct |
42 |
Correct |
100 ms |
20600 KB |
Output is correct |
43 |
Correct |
106 ms |
20728 KB |
Output is correct |
44 |
Correct |
100 ms |
20748 KB |
Output is correct |
45 |
Correct |
106 ms |
20596 KB |
Output is correct |
46 |
Correct |
105 ms |
20600 KB |
Output is correct |
47 |
Correct |
103 ms |
20728 KB |
Output is correct |
48 |
Correct |
109 ms |
20712 KB |
Output is correct |
49 |
Correct |
103 ms |
20728 KB |
Output is correct |
50 |
Correct |
103 ms |
20680 KB |
Output is correct |
51 |
Correct |
101 ms |
20700 KB |
Output is correct |
52 |
Correct |
110 ms |
20592 KB |
Output is correct |
53 |
Correct |
108 ms |
20668 KB |
Output is correct |
54 |
Correct |
109 ms |
20600 KB |
Output is correct |
55 |
Correct |
107 ms |
20728 KB |
Output is correct |
56 |
Correct |
112 ms |
20844 KB |
Output is correct |
57 |
Correct |
111 ms |
20704 KB |
Output is correct |
58 |
Correct |
101 ms |
20576 KB |
Output is correct |
59 |
Correct |
99 ms |
20600 KB |
Output is correct |
60 |
Correct |
113 ms |
20600 KB |
Output is correct |