Submission #1722206


Source Code Expand

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

struct gausselim
{
	int rank;
	pair<ll,ll> cyc[31];
	void init()
	{
		for(int i = 0; i < 31; i++)
		{
			cyc[i] = mp(0,0);
		}
		rank = 0;
	}
	void add(ll x)
	{
		int tmp = 0;
		for(int i = 30; i >= 0; i--)
		{
			if(x&(1<<i))
			{
				if(cyc[i].fi==0)
				{
					cyc[i].fi = x;
					cyc[i].se = (1<<i)^tmp;
					rank++;
					break;
				}
			}
			//x = min(x, (x^cyc[i]));
			if((x^cyc[i].fi)<x)
			{
				x^=cyc[i].fi;
				tmp^=cyc[i].se;
			}
		}	
	}
};
gausselim base;
vi vec;
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	int s = 0;
	for(int i = 0; i < n; i++)
	{
		int x; cin>>x;
		vec.pb(x^(x-1));
		s^=x;
	}
	//how many of vec[i] xors to x;
	for(int i = 0; i < n; i++)
	{
		base.add(vec[i]);
	}
	ll tmp = 0;
	int x = 0;
	for(int i = 30; i >= 0; i--)
	{
		if(base.cyc[i].fi==0) continue;
		if((s&(1<<i)) != (x&(1<<i)))
		{
			x^=base.cyc[i].fi;
			tmp^=base.cyc[i].se;
		}
	}
	if(x!=s) cout<<-1<<'\n';
	else cout<<__builtin_popcount(tmp)<<'\n';
}

Submission Info

Submission Time
Task C - Cheating Nim
User vjudge2
Language C++14 (GCC 5.4.1)
Score 500
Code Size 1558 Byte
Status AC
Exec Time 19 ms
Memory 892 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 26
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 1 ms 256 KB
001.txt AC 1 ms 256 KB
002.txt AC 19 ms 892 KB
003.txt AC 10 ms 640 KB
004.txt AC 9 ms 640 KB
005.txt AC 6 ms 512 KB
006.txt AC 19 ms 892 KB
007.txt AC 19 ms 892 KB
008.txt AC 19 ms 892 KB
009.txt AC 19 ms 892 KB
010.txt AC 19 ms 892 KB
011.txt AC 19 ms 892 KB
012.txt AC 19 ms 892 KB
013.txt AC 19 ms 892 KB
014.txt AC 19 ms 892 KB
015.txt AC 19 ms 892 KB
016.txt AC 19 ms 892 KB
017.txt AC 19 ms 892 KB
018.txt AC 19 ms 892 KB
019.txt AC 19 ms 892 KB
020.txt AC 19 ms 892 KB
021.txt AC 3 ms 384 KB
022.txt AC 3 ms 384 KB
023.txt AC 18 ms 892 KB
example0.txt AC 1 ms 256 KB
example1.txt AC 1 ms 256 KB