arc168b

发布时间 2023-11-26 22:57:02作者: gan_coder

https://atcoder.jp/contests/arc168/tasks/arc168_b
不会博弈,但是会乱搞

首先直接判断-1的情况
然后我们直接考察最大值能不能取到

假设存在一个数ai
\(a_1\oplus a_2 ...\oplus(a_i-x)\oplus...a_n\)=max
也就是说要拿掉max,才能再使xor=0
移项之后得到
\((a_i-x)=a_1\oplus a_2 ...\oplus...a_n\oplus max\)
设max的最高位是第j位
如果\(a_i\)与max的最高位相同,那么右边第j位显然为0,那么一定可以取到,但是有个前提就是x不为0

对于那些出现偶数次的最大值直接去掉即可,因为bob可以模仿Alice。
说得非常抽象。

#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<ctime>
#define A puts("YES")
#define B puts("NO")
//#define A puts("Yes")
//#define B puts("No")
#define fo(i,a,b) for (int (i)=(a);(i)<=(b);(i)++)
#define fd(i,b,a) for (int (i)=(b);(i)>=(a);(i)--)
#define mk(x,y) make_pair((x),(y))
#define lc (o<<1)
#define rc (o<<1|1)
using namespace std;
//typedef __int128 i128;
typedef double db;
typedef long long ll;
const ll inf=1ll<<60;
const int N=1e6+5;
int n,b[50],a[N];
int main()
{
//	freopen("data.in","r",stdin);
//	freopen("ans.out","w",stdout);
	
	b[0]=1;
	fo(i,1,30) b[i]=b[i-1]*2;
	
	scanf("%d",&n);
	fo(i,1,n) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	
	int s=0;
	fo(i,1,n) s^=a[i];
	
	if (s) {
		puts("-1");
		return 0;
	}

	while (n>1 && a[n]==a[n-1]) n-=2;
	if (!n) {
		puts("0");
		return 0;
	}
	
	printf("%d",a[n]-1);
	return 0;
}