Submission #1955657


Source Code Expand

import java.util.Arrays;
import java.util.Scanner;

class Main {
	int n;
	long[] a;
	long grundy = 0;

	void run() {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		a = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextInt();
			grundy ^= a[i];
		}
		boolean[] flip = new boolean[64];
		for (int i = 0; i < n; ++i) {
			flip[cnt(a[i] & -a[i])] = true;
		}
		int ans = 0;
		while (grundy > 0) {
			long c = 1;
			while (2 * c <= grundy) {
				c <<= 1;
			}
			if (!flip[cnt(c)]) {
				System.out.println(-1);
				return;
			} else {
				++ans;
				while (c > 0) {
					grundy ^= c;
					c /= 2;
				}
			}
		}
		System.out.println(ans);
	}

	int cnt(long x) {
		int ret = 0;
		while (x > 0) {
			++ret;
			x /= 2;
		}
		return ret;
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Submission Info

Submission Time
Task C - Cheating Nim
User fortoobye
Language Java8 (OpenJDK 1.8.0)
Score 500
Code Size 970 Byte
Status AC
Exec Time 534 ms
Memory 50100 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 97 ms 19284 KB
001.txt AC 98 ms 19156 KB
002.txt AC 463 ms 48632 KB
003.txt AC 352 ms 40924 KB
004.txt AC 355 ms 44136 KB
005.txt AC 338 ms 40248 KB
006.txt AC 534 ms 45936 KB
007.txt AC 509 ms 49788 KB
008.txt AC 523 ms 48032 KB
009.txt AC 526 ms 47316 KB
010.txt AC 523 ms 47736 KB
011.txt AC 490 ms 46040 KB
012.txt AC 517 ms 46236 KB
013.txt AC 514 ms 47708 KB
014.txt AC 501 ms 47052 KB
015.txt AC 506 ms 47192 KB
016.txt AC 522 ms 50100 KB
017.txt AC 510 ms 48584 KB
018.txt AC 495 ms 46344 KB
019.txt AC 510 ms 45556 KB
020.txt AC 480 ms 43420 KB
021.txt AC 212 ms 32220 KB
022.txt AC 214 ms 31396 KB
023.txt AC 506 ms 48356 KB
example0.txt AC 98 ms 23124 KB
example1.txt AC 98 ms 19796 KB