# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1055967 | tamir1 | Xylophone (JOI18_xylophone) | C++17 | 34 ms | 712 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include "xylophone.h"
using namespace std;
static int A[5001];
int x[5001],y[5001];
void solve(int N) {
int l=1,r=N,mid,i,mx=1,idx=0;
while(r>l){
mid=(r+l+1)/2;
if(query(mid,N)==N-1) l=mid;
else r=mid-1;
}
A[l]=1;
for(i=2;i<=N;i++) x[i]=query(i-1,i);
for(i=3;i<=N;i++) y[i]=query(i-2,i);
if(l<N) A[l+1]=x[l+1]+1;
for(i=l+2;i<=N;i++){
if(x[i-1]==y[i]){
if(A[i-1]>A[i-2]) A[i]=A[i-1]-x[i];
else A[i]=A[i-1]+x[i];
}
else{
if(y[i]!=x[i]){
if(A[i-1]>A[i-2]) A[i]=A[i-1]+x[i];
else A[i]=A[i-1]-x[i];
}
else{
if(A[i-2]>A[i-1]) A[i]=A[i-1]+x[i];
else A[i]=A[i-1]-x[i];
}
}
}
if(l>1) A[l-1]=x[l]+1;
for(i=l-2;i>=1;i--){
if(x[i+2]==y[i+2]){
if(A[i+1]>A[i+2]) A[i]=A[i+1]-x[i+1];
else A[i]=A[i+1]+x[i+1];
}
else{
if(y[i+2]!=x[i+1]){
if(A[i+1]>A[i+2]) A[i]=A[i+1]+x[i+1];
else A[i]=A[i+1]-x[i+1];
}
else{
if(A[i+2]>A[i+1]) A[i]=A[i+1]+x[i+1];
else A[i]=A[i+1]-x[i+1];
}
}
}
for(i=1;i<=N;i++){
answer(i,A[i]);
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |