이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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
컴파일 시 표준 에러 (stderr) 메시지
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]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |