Submission #3468773
Source Code Expand
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws IOException {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskX solver = new TaskX();
solver.solve(1, in, out);
out.close();
}
static int INF = 1 << 30;
static long LINF = 1L << 55;
static int MOD = 1000000007;
static int[] mh4 = { 0, -1, 1, 0 };
static int[] mw4 = { -1, 0, 0, 1 };
static int[] mh8 = { -1, -1, -1, 0, 0, 1, 1, 1 };
static int[] mw8 = { -1, 0, 1, -1, 1, -1, 0, 1 };
static class TaskX {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
long x = 0;
long[] a = new long[n], bit = new long[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextLong();
x ^= a[i];
bit[i] = a[i] ^ (a[i]-1);
}
Arrays.sort(bit);
int count = 0;
for (int k = 32; k >= 0; k--) {
if ((x >> (k-1) & 1) == 1) {
for (int i = 0; i < n; i++) {
int pos = Arrays.binarySearch(bit, (1L << k) - 1);
if (pos >= 0) {
x ^= bit[pos];
count++;
break;
}
}
}
}
out.println(x == 0 ? count : -1);
}
}
static class InputReader {
BufferedReader in;
StringTokenizer tok;
public String nextString() {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine(), " ");
} catch (IOException e) {
throw new InputMismatchException();
}
}
return tok.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextString());
}
public long nextLong() {
return Long.parseLong(nextString());
}
public double nextDouble() {
return Double.parseDouble(nextString());
}
public int[] nextIntArray(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt();
}
return res;
}
public int[] nextIntArrayDec(int n) {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = nextInt() - 1;
}
return res;
}
public int[] nextIntArray1Index(int n) {
int[] res = new int[n + 1];
for (int i = 0; i < n; i++) {
res[i + 1] = nextInt();
}
return res;
}
public long[] nextLongArray(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong();
}
return res;
}
public long[] nextLongArrayDec(int n) {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nextLong() - 1;
}
return res;
}
public long[] nextLongArray1Index(int n) {
long[] res = new long[n + 1];
for (int i = 0; i < n; i++) {
res[i + 1] = nextLong();
}
return res;
}
public double[] nextDoubleArray(int n) {
double[] res = new double[n];
for (int i = 0; i < n; i++) {
res[i] = nextDouble();
}
return res;
}
public InputReader(InputStream inputStream) {
in = new BufferedReader(new InputStreamReader(inputStream));
tok = new StringTokenizer("");
}
}
}
Submission Info
Submission Time |
|
Task |
C - Cheating Nim |
User |
tutuz |
Language |
Java8 (OpenJDK 1.8.0) |
Score |
500 |
Code Size |
3459 Byte |
Status |
AC |
Exec Time |
206 ms |
Memory |
36756 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
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 |
72 ms |
18516 KB |
001.txt |
AC |
71 ms |
18388 KB |
002.txt |
AC |
182 ms |
35088 KB |
003.txt |
AC |
155 ms |
30972 KB |
004.txt |
AC |
187 ms |
29844 KB |
005.txt |
AC |
154 ms |
28068 KB |
006.txt |
AC |
197 ms |
36428 KB |
007.txt |
AC |
193 ms |
35312 KB |
008.txt |
AC |
192 ms |
36116 KB |
009.txt |
AC |
191 ms |
36536 KB |
010.txt |
AC |
190 ms |
35812 KB |
011.txt |
AC |
191 ms |
34952 KB |
012.txt |
AC |
191 ms |
33016 KB |
013.txt |
AC |
188 ms |
35252 KB |
014.txt |
AC |
190 ms |
34176 KB |
015.txt |
AC |
197 ms |
34900 KB |
016.txt |
AC |
204 ms |
35672 KB |
017.txt |
AC |
206 ms |
31996 KB |
018.txt |
AC |
190 ms |
34232 KB |
019.txt |
AC |
188 ms |
33388 KB |
020.txt |
AC |
200 ms |
36756 KB |
021.txt |
AC |
124 ms |
22996 KB |
022.txt |
AC |
121 ms |
23124 KB |
023.txt |
AC |
200 ms |
36164 KB |
example0.txt |
AC |
71 ms |
19028 KB |
example1.txt |
AC |
71 ms |
18772 KB |