이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include <xylophone.h>
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
using namespace std;
int a[5009];
int pos[5009];
void solve(int n){
for (int i=1;i<=n;i++){
pos[i]=0;
}
int l=1,r=n;
int pos1=1;
while (l<=r){
int mid=(l+r)/2;
int dd=query(mid,n);
if (dd==n-1){
l=mid+1;
pos1=mid;
}
else {
r=mid-1;
}
}
a[pos1]=1;
pos[1]=1;
answer(pos1,1);
if (pos1<n){
a[pos1+1]=query(pos1,pos1+1)+1;
pos[a[pos1+1]]=1;
answer(pos1+1,a[pos1+1]);
}
if (pos1>1){
a[pos1-1]=query(pos1-1,pos1)+1;
pos[a[pos1-1]]=1;
answer(pos1-1,a[pos1-1]);
}
for (int i=pos1+2;i<=n;i++){
int d=query(i-1,i);
if (a[i-1]+d>n){
a[i]=a[i-1]-d;
}
else if (a[i-1]-d<0){
a[i]=a[i-1]+d;
}
if (a[i-1]+d<=n&&a[i-1]-d>0){
if (pos[a[i-1]+d]==1){
a[i]=a[i-1]-d;
}
else if (pos[a[i-1]-d]==1){
a[i]=a[i-1]+d;
}
else if (pos[a[i-1]-d]==0&&pos[a[i-1]+d]==0){
int rr=query(i-2,i);
int l1=a[i-1]-d;
if (max({l1,a[i-1],a[i-2]})-min({l1,a[i-1],a[i-2]})==rr){
a[i]=a[i-1]-d;
}
else {
a[i]=a[i-1]+d;
}
}
}
pos[a[i]]=1;
answer(i,a[i]);
}
for (int i=pos1-2;i>=1;i--){
int d=query(i,i+1);
if (a[i+1]+d>n){
a[i]=a[i+1]-d;
}
else if (a[i+1]-d<0){
a[i]=a[i+1]+d;
}
if (a[i+1]+d<=n&&a[i+1]-d>0){
if (pos[a[i+1]+d]==1){
a[i]=a[i+1]-d;
}
else if (pos[a[i+1]-d]==1){
a[i]=a[i+1]+d;
}
else if (pos[a[i+1]-d]==0&&pos[a[i+1]+d]==0){
int rr=query(i+2,i);
int l1=a[i+1]-d;
if (a[i+1]<a[i+2]){
if (a[i+2]-l1==rr){
a[i]=l1;
}
else {
a[i]=a[i+1]+d;
}
}
else {
if (l1<a[i+2]){
if (rr==d){
a[i]=l1;
}
else {
a[i]=a[i+1]+d;
}
}
else {
if (a[i+1]-a[i+2]==rr){
a[i]=l1;
}
else a[i]=a[i+1]+d;
}
}
}
}
pos[a[i]]=1;
answer(i,a[i]);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |