이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "xylophone.h"
#include<cmath>
static int A[5000];
using namespace std;
void solve(int N) {
int n=N;
int value = query(1, N);
int pf;
// cout<<" find first "<<endl;
for(int i=1;i<=n;i++){
int t=query(i,N);
if(t!=n-1){
pf=i-1;
break;
}
}
//cout<<pf<<endl;
answer(pf,1);
// cout<<"os edo"<<endl;
int a[n+3]={};
a[pf]=1;
if(pf!=1){
a[pf-1] = query(pf-1,pf)+1;
answer(pf-1,a[pf-1]);
}
if(pf!=N){
a[pf+1] = query(pf,pf+1)+1;
answer(pf+1,a[pf+1]);
}
// cout<<"my answer "<<endl;
//for(int i = 1; i <= N; i++) {
// cout<<a[i]<<" ";
//}
int s=pf+2;
while(s<=n){
int t=query(s-1,s);
int t2=query(s-2,s);
if(abs(a[s-1]-a[s-2])==t2){
if(a[s-1] > a[s-2]){
a[s]=a[s-1]-t;
answer(s,a[s]);
}
else{
a[s]=a[s-1]+t;
answer(s,a[s]);
}
}
else
{
if(a[s-1] > a[s-2]){
if(a[s-1]-a[s-2] + t == t2){
a[s]=a[s-1]+t;
answer(s,a[s]);
}
else
{
a[s]=a[s-1]-t;
answer(s,a[s]);
}
}
else{
if(a[s-2]-a[s-1] + t == t2){
a[s]=a[s-1]-t;
answer(s,a[s]);
}
else
{
a[s]=a[s-1]+t;
answer(s,a[s]);
}
}
}
// cout<<"my answer "<<endl;
//for(int i = 1; i <= N; i++) {
// cout<<a[i]<<" ";
//}
s++;
}
s=pf-2;
while(s>=1){
int t=query(s,s+1);
int t2=query(s,s+2);
if(abs(a[s+1]-a[s+2])==t2){
if(a[s+1] > a[s+2]){
a[s]=a[s+1]-t;
answer(s,a[s]);
}
else{
a[s]=a[s+1]+t;
answer(s,a[s]);
}
}
else
{
if(a[s+1] > a[s+2]){
if(a[s+1]-a[s+2] + t == t2){
a[s]=a[s+1]+t;
answer(s,a[s]);
}
else
{
a[s]=a[s+1]-t;
answer(s,a[s]);
}
}
else{
if(a[s+2]-a[s+1] + t == t2){
a[s]=a[s+1]-t;
answer(s,a[s]);
}
else
{
a[s]=a[s+1]+t;
answer(s,a[s]);
}
}
}
// cout<<"my answer "<<endl;
// for(int i = 1; i <= N; i++) {
// cout<<a[i]<<" ";
// }
s--;
}
// cout<<"my answer "<<endl;
//for(int i = 1; i <= N; i++) {
// cout<<a[i]<<" ";
//}
}
컴파일 시 표준 에러 (stderr) 메시지
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:9:6: warning: unused variable 'value' [-Wunused-variable]
int value = query(1, N);
^~~~~
xylophone.cpp: At global scope:
xylophone.cpp:3:12: warning: 'A' defined but not used [-Wunused-variable]
static int A[5000];
^
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:28:5: warning: 'pf' may be used uninitialized in this function [-Wmaybe-uninitialized]
if(pf!=N){
^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |