# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
501784 | lovrot | Xylophone (JOI18_xylophone) | C++11 | 0 ms | 0 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>
using namespace std;
int rj[10000];
int main (){
int n;
cin >> n;
int p;
for (int i=n;i>0;i--){
cout<<"query("<<1<<", "<<i<<")"<<endl;
int odg;
cin>>odg;
if (odg<n-1){
rj[i+1]=n;
p=i+1;
break;
}
}
if (n!=p){
cout<<"query("<<p<<", "<<p+1<<")"<<endl;
int odg;
cin>>odg;
rj[p+1]=n-odg;
}
if (1!=p){
cout<<"query("<<p<<", "<<p-1<<")"<<endl;
int odg;
cin>>odg;
rj[p-1]=n-odg;
}
for (int i=p+2;i<n+1;i++){
cout<<"query("<<i-1<<", "<<i<<")"<<endl;
int odg1;
cin>>odg1;
cout<<"query("<<i-2<<", "<<i<<")"<<endl;
int odg2;
cin>>odg2;
if (rj[i-1]>rj[i-2]){
if (odg2==rj[i-1]-rj[i-2]+odg1){
rj[i]=rj[i-1]+odg1;
}
else {
rj[i]=rj[i-1]-odg1;
}
}
else {
if (odg2==rj[i-2]-rj[i-1]+odg1){
rj[i]=rj[i-1]-odg1;
}
else {
rj[i]=rj[i-1]+odg1;
}
}
}
for (int i=p-2;i>0;i--){
cout<<"query("<<i+1<<", "<<i<<")"<<endl;
int odg1;
cin>>odg1;
cout<<"query("<<i+2<<", "<<i<<")"<<endl;
int odg2;
cin>>odg2;
if (rj[i+1]>rj[i+2]){
if (odg2==rj[i+1]-rj[i+2]+odg1){
rj[i]=rj[i+1]+odg1;
}
else {
rj[i]=rj[i+1]-odg1;
}
}
else {
if (odg2==rj[i+2]-rj[i+1]+odg1){
rj[i]=rj[i+1]-odg1;
}
else {
rj[i]=rj[i+1]+odg1;
}
}
}
for (int i=1;i<n+1;i++){
cout<<rj[i]<<" ";
}
return 0;
}