Codeforces Round #427 (Div. 2), problem: (E) The penguin’s game Solution In C/C++

#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;
const int N=1010;
int n,x,y,bit,ans;
int cnta,cntb;
int a[N],b[N];
int ans1,ans2;

int gao(int *a,int l,int r){
if (r-l+1==0) return 0;
printf(“? %d “,r-l+1);
for (int i=l;i<=r;i++)
printf(“%d “,a[i]);
printf(“\n”);
fflush(stdout);
int res;
scanf(“%d”,&res);
return res;
}

int find(int *a,int cnt){
int l=1,r=cnt,ans=cnt;
while (l<r){
int mid=(l+r)>>1;
int res=gao(a,l,mid);
if (res==y || res==(x^y))
ans=mid,r=mid; else
ans=mid+1,l=mid+1;
}
return a[ans];
}

int main(){
// freopen(“a.in”,”r”,stdin);
scanf(“%d%d%d”,&n,&x,&y);
for (int i=0;i<=9;i++){
cnta=0;
for (int j=1;j<=n;j++)
if (j&(1<<i))
a[++cnta]=j;
int res=gao(a,1,cnta);
if (res==y || res==(x^y)){
ans|=1<<i;
bit=i;
}
}
cnta=cntb=0;
for (int i=1;i<=n;i++)
if (i&(1<<bit))
a[++cnta]=i; else
b[++cntb]=i;
if (cnta>cntb)
ans1=find(b,cntb); else
ans1=find(a,cnta);
ans2=ans1^ans;
if (ans1>ans2)
swap(ans1,ans2);
printf(“! %d %d\n”,ans1,ans2);
}

Is Desk Productivity Tools...

📢 As an Amazon Associate, I earn from qualifying...

The Outer Worlds 2...

Gamers and RPG enthusiasts have reason to celebrate as...

Why Travel Organization Gear...

📢 As an Amazon Associate, I earn from qualifying...

Why Everyone Is Talking...

📢 As an Amazon Associate, I earn from qualifying...

Why Everyone Is Talking...

📢 As an Amazon Associate, I earn from qualifying...

Why Everyone Is Talking...

📢 As an Amazon Associate, I earn from qualifying...

Is Desk Productivity Tools Worth Your Money Here Is Our Full Review

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Desk Productivity Tools?The Desk Productivity Tools...

The Outer Worlds 2 v1.2.0.1-TENOKE

Gamers and RPG enthusiasts have reason to celebrate as Obsidian Entertainment's acclaimed franchise returns with new developments. The highly anticipated sequel to the award-winning...

Why Travel Organization Gear Is Currently Breaking the Internet

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

Why Everyone Is Talking About the Car Detailing Essentials

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Car Detailing Essentials?The Car Detailing Essentials...

Why Everyone Is Talking About the Smart Home Hacks

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Smart Home Hacks?The Smart Home Hacks...

Why Everyone Is Talking About the Viral Kitchen Gadgets

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Viral Kitchen Gadgets?The Viral Kitchen Gadgets...

Why Everyone Is Talking About the Travel Organization Gear

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

Why Everyone Is Talking About the Travel Organization Gear

📢 As an Amazon Associate, I earn from qualifying purchases.💰 Official Price: Check on Amazon🌟 Why Buy the Travel Organization Gear?The Travel Organization Gear...

GLP-1 Drugs Like Ozempic Carry Elevated Risks of Muscle Loss and Malnutrition in Adults Over 65

Understanding the Risks of GLP-1 Drugs for Older Adults GLP-1 receptor agonists, such as Ozempic, Wegovy, and Mounjaro, have transformed the landscape of weight management...