~~~~~
static ArrayList qu= new ArrayList<>(); static void pre(int n) { int i=1; while(i<= n) { qu.add(i); i*=2; } } static void solve(int cct, int tcc) throws IOException {
int n= in.nextInt();
pre(n);
HashSet<Integer> fin= new HashSet<>();
HashSet<Integer> one = new HashSet<>();
HashSet<Integer>zero = new HashSet<>();
StringBuilder ans= new StringBuilder();
for(int i=1;i<n;i++)
{
fin.add(i);
}
int sc=1;
for(int i : qu)
{
for(int j : fin)
{
out.println("? "+j+" "+i);
out.flush();
int x = in.nextInt();
if(x==0)zero.add(j);
else
one.add(j);
}// out.print(zero); // out.println(one);
if(zero.size()<one.size())
{
ans.insert(0, '0');
fin=zero;
if(fin.isEmpty()){
break;
}
}
else if(zero.size()== one.size())
{
ans.insert(0,sc);
if(sc==0)
fin=zero;
else
fin=one;
}
else
{
ans.insert(0, '1');
fin=one;
if(fin.isEmpty()){
ans.insert(0,'0');
break;
}
}
sc++;
sc= sc%2;
one=new HashSet<>();
zero=new HashSet<>();// out.println(fin); // out.println(ans); } // out.println(ans); String a =""; for(int i=0;i<ans.length();i++) { if(ans.charAt(i)=='1') { a=ans.substring(i); break; } }
int number = Integer.parseInt(a, 2);
out.println("! "+number);
out.flush();// 1 2 4 3 5
}~~~~~
Can someone please let me know whats wrong with this solution of D ????
It is failing for 1 2 3 4 5 But on IDE i got correct answer









Auto comment: topic has been updated by -delta (previous revision, new revision, compare).
Sorry, but I can't help you!
Because I don't know how to do D :>