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<iostream>
#include "xylophone.h"
using namespace std;
bool bylo[100000];
int jaki[100000];
/*int query(int x,int y)
{
cout<<x<<" "<<y<<"\n";
int co;
cin>>co;
return co;
}
int answer(int x,int y)
{
cout<<y<<" ";
}*/
void solve(int n)
{
int pocz=1,kon=n+1,sre,ostd;
int szukam=n-1;
int mam=0;
while(pocz<kon)
{
sre=(pocz+kon)/2;
int k=query(sre,n);
mam++;
if(k==n-1)
{
ostd=sre;
pocz=sre+1;
}
else{
kon=sre;
}
}
jaki[ostd]=1;
bylo[1]=1;
for(int i=ostd+1;i<=n;i++)
{
if(mam==10000-1)
{
while(true)
mam++;
}
int k=query(i-1,i);
mam++;
if(jaki[i-1]-k<=0 || bylo[jaki[i-1]-k]==1)
jaki[i]=jaki[i-1]+k;
else if(jaki[i-1]+k>n || bylo[jaki[i-1]+k]==1)
jaki[i]=jaki[i-1]-k;
else{
if(mam==10000-1)
{
while(true)
mam++;
}
int k1=query(ostd,i);
mam++;
if(k1==jaki[i-1]-1)
jaki[i]=jaki[i-1]-k;
else jaki[i]=jaki[i-1]+k;
}
bylo[jaki[i]]=1;
}
for(int i=ostd-1;i>=1;i--)
{
if(mam==10000-1)
{
while(true)
mam++;
}
int k=query(i,i+1);
mam++;
if(jaki[i+1]-k<=0 || bylo[jaki[i+1]-k]==1)
jaki[i]=jaki[i+1]+k;
else if(jaki[i+1]+k>n || bylo[jaki[i+1]+k]==1)
jaki[i]=jaki[i+1]-k;
else{
if(mam==10000-1)
{
while(true)
mam++;
}
int k1=query(i,ostd);
mam++;
if(k1==jaki[i+1]-1)
jaki[i]=jaki[i+1]-k;
else jaki[i]=jaki[i+1]+k;
}
bylo[jaki[i]]=1;
}
for(int i=1;i<=n;i++)
answer(i,jaki[i]);
}
Compilation message (stderr)
xylophone.cpp: In function 'void solve(int)':
xylophone.cpp:20:9: warning: unused variable 'szukam' [-Wunused-variable]
20 | int szukam=n-1;
| ^~~~~~
xylophone.cpp:36:15: warning: 'ostd' may be used uninitialized in this function [-Wmaybe-uninitialized]
36 | jaki[ostd]=1;
| ~~~~~~~~~~^~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |