Submission #3468749


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.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);
			}

			int count = 0;
			for (int k = 32; k >= 0; k--) {
				if ((x >> (k-1) & 1) == 1) {
					for (int i = 0; i < n; i++) {
						if (bit[i] == (1L << k) - 1) {
							x ^= bit[i];
							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 3366 Byte
Status AC
Exec Time 182 ms
Memory 36952 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 70 ms 19412 KB
001.txt AC 71 ms 21460 KB
002.txt AC 173 ms 36392 KB
003.txt AC 143 ms 28244 KB
004.txt AC 147 ms 28100 KB
005.txt AC 137 ms 27432 KB
006.txt AC 173 ms 34948 KB
007.txt AC 182 ms 36668 KB
008.txt AC 175 ms 36408 KB
009.txt AC 169 ms 34100 KB
010.txt AC 174 ms 36596 KB
011.txt AC 176 ms 35484 KB
012.txt AC 173 ms 36116 KB
013.txt AC 173 ms 35108 KB
014.txt AC 174 ms 35620 KB
015.txt AC 177 ms 36368 KB
016.txt AC 173 ms 36264 KB
017.txt AC 175 ms 34232 KB
018.txt AC 165 ms 36952 KB
019.txt AC 170 ms 34700 KB
020.txt AC 176 ms 33716 KB
021.txt AC 109 ms 24660 KB
022.txt AC 114 ms 24532 KB
023.txt AC 173 ms 34932 KB
example0.txt AC 70 ms 18388 KB
example1.txt AC 71 ms 20948 KB