# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197502 | handlename | Xylophone (JOI18_xylophone) | C++17 | 116 ms | 512 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 "xylophone.h"
#include <bits/stdc++.h>
using namespace std;
int n,arr[5001][2];
int queries[5001][2];
void solve(int N){
n=N;
for (int j=0;j<2;j++){
int temp;
if (queries[2][0]!=0){
temp=queries[2][0];
}
else {
temp=query(1,2);
queries[2][0]=temp;
}
if (j==0) arr[2][j]=arr[1][j]+temp;
else arr[2][j]=arr[1][j]-temp;
for (int i=3;i<=n;i++){
int one;
int two;
if (queries[i][0]!=0){
one=queries[i][0];
two=queries[i][1];
}
else {
one=query(i-1,i);
two=query(i-2,i);
queries[i][0]=one;
queries[i][1]=two;
}
int diff=abs(arr[i-1][j]-arr[i-2][j]);
if (arr[i-1][j]>arr[i-2][j]){
if (one+diff==two){
arr[i][j]=arr[i-1][j]+one;
}
else arr[i][j]=arr[i-1][j]-one;
}
else {
if (one+diff==two){
arr[i][j]=arr[i-1][j]-one;
}
else arr[i][j]=arr[i-1][j]+one;
}
}
bool works=true;
int mini=1e9,lpos,rpos;
for (int i=1;i<=n;i++) mini=min(mini,arr[i][j]);
for (int i=1;i<=n;i++){
arr[i][j]+=(1-mini);
if (arr[i][j]<1 || arr[i][j]>n) works=false;
if (arr[i][j]==1) lpos=i;
if (arr[i][j]==n) rpos=i;
}
if (lpos>rpos) works=false;
if (works){
for (int i=1;i<=n;i++) answer(i,arr[i][j]);
}
}
}
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... |