Submission #552412


Source Code Expand

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {
	static InputStream is;
	static PrintWriter out;
	static String INPUT = "";
	
	static void solve()
	{
		int n = ni();
		int[] a = na(n);
		int[] pos = new int[n];
		int[] neg = new int[n];
		int p = 0, q = 0;
		for(int i = 0;i < n;i++){
			if(a[i] > 0){
				pos[p++] = a[i]-1;
			}else{
				neg[q++] = -a[i]-1;
			}
		}
		pos = Arrays.copyOf(pos, p);
		neg = Arrays.copyOf(neg, q);
//		out.println((nimSatoWelterSymmetrically(pos)^nimSatoWelterSymmetrically(neg)) == 0 ? "Ben" : "Alyssa");
		out.println((nimSatoWelterAsymmetrically(pos)^nimSatoWelterAsymmetrically(neg)) == 0 ? "Ben" : "Alyssa");
	}
	
	static long nimSatoWelterSymmetrically(int[] a)
	{
		int nim = 0;
		for(int v : a)nim ^= v;
		for(int i = 0;i < a.length;i++){
			for(int j = i+1;j < a.length;j++){
				nim ^= (a[i]^a[j])^(a[i]^a[j])-1;
			}
		}
		return nim;
	}
	
	static long nimSatoWelterAsymmetrically(int[] a)
	{
		int n = a.length;
		for(int i = 0;i < n;i++){
			a[i] = Integer.reverse(a[i]<<2);
		}
		Arrays.sort(a);
		int nim = 0;
		for(int d = 10;d < 31;d++){
			int p = 0;
			for(int i = 0;i < n;i++){
				if(i < n-1 && ((a[i]^a[i+1])>>>d) == 0){
					nim ^= (Integer.reverse(a[i]^a[i+1])>>>2)-1;
					i++;
				}else{
					a[p++] = a[i];
				}
			}
			n = p;
		}
		if(n > 0)nim ^= (Integer.reverse(a[0])>>>2);
		return nim;
	}
	
	public static void main(String[] args) throws Exception
	{
		long S = System.currentTimeMillis();
		is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);
		
		solve();
		out.flush();
		long G = System.currentTimeMillis();
		tr(G-S+"ms");
	}
	
	private static boolean eof()
	{
		if(lenbuf == -1)return true;
		int lptr = ptrbuf;
		while(lptr < lenbuf)if(!isSpaceChar(inbuf[lptr++]))return false;
		
		try {
			is.mark(1000);
			while(true){
				int b = is.read();
				if(b == -1){
					is.reset();
					return true;
				}else if(!isSpaceChar(b)){
					is.reset();
					return false;
				}
			}
		} catch (IOException e) {
			return true;
		}
	}
	
	private static byte[] inbuf = new byte[1024];
	static int lenbuf = 0, ptrbuf = 0;
	
	private static int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}
	
	private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
//	private static boolean isSpaceChar(int c) { return !(c >= 32 && c <= 126); }
	private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
	
	private static double nd() { return Double.parseDouble(ns()); }
	private static char nc() { return (char)skip(); }
	
	private static String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	private static char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}
	
	private static char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}
	
	private static int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}
	
	private static int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}
		
		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
	
	private static void tr(Object... o) { if(INPUT.length() != 0)System.out.println(Arrays.deepToString(o)); }
}

Submission Info

Submission Time
Task L - コインゲーム
User uwi
Language Java (OpenJDK 1.7.0)
Score 400
Code Size 4678 Byte
Status AC
Exec Time 495 ms
Memory 25104 KB

Judge Result

Set Name Small All
Score / Max Score 30 / 30 370 / 370
Status
AC × 32
AC × 93
Set Name Test Cases
Small 00_sample_small_00.txt, 00_sample_small_01.txt, 11_small_00.txt, 11_small_01.txt, 11_small_02.txt, 11_small_03.txt, 11_small_04.txt, 11_small_05.txt, 11_small_06.txt, 11_small_07.txt, 11_small_08.txt, 11_small_09.txt, 14_small_10.txt, 14_small_11.txt, 14_small_12.txt, 14_small_13.txt, 14_small_14.txt, 14_small_15.txt, 14_small_16.txt, 14_small_17.txt, 14_small_18.txt, 14_small_19.txt, 14_small_20.txt, 14_small_21.txt, 14_small_22.txt, 14_small_23.txt, 14_small_24.txt, 14_small_25.txt, 14_small_26.txt, 14_small_27.txt, 14_small_28.txt, 14_small_29.txt
All 00_sample_small_00.txt, 00_sample_small_01.txt, 11_small_00.txt, 11_small_01.txt, 11_small_02.txt, 11_small_03.txt, 11_small_04.txt, 11_small_05.txt, 11_small_06.txt, 11_small_07.txt, 11_small_08.txt, 11_small_09.txt, 14_small_10.txt, 14_small_11.txt, 14_small_12.txt, 14_small_13.txt, 14_small_14.txt, 14_small_15.txt, 14_small_16.txt, 14_small_17.txt, 14_small_18.txt, 14_small_19.txt, 14_small_20.txt, 14_small_21.txt, 14_small_22.txt, 14_small_23.txt, 14_small_24.txt, 14_small_25.txt, 14_small_26.txt, 14_small_27.txt, 14_small_28.txt, 14_small_29.txt, 50_random_30.txt, 50_random_31.txt, 50_random_32.txt, 50_random_33.txt, 50_random_34.txt, 50_random_35.txt, 50_random_36.txt, 50_random_37.txt, 50_random_38.txt, 50_random_39.txt, 50_sample_00.txt, 60_Alyssa_41.txt, 60_Alyssa_42.txt, 60_Alyssa_43.txt, 60_Alyssa_48.txt, 60_Alyssa_51.txt, 60_Alyssa_52.txt, 60_Alyssa_54.txt, 60_Alyssa_55.txt, 60_Alyssa_57.txt, 60_Alyssa_58.txt, 60_Alyssa_59.txt, 60_Alyssa_62.txt, 60_Alyssa_64.txt, 60_Alyssa_65.txt, 60_Alyssa_66.txt, 60_Alyssa_67.txt, 60_Alyssa_68.txt, 60_Alyssa_69.txt, 60_Alyssa_70.txt, 60_Alyssa_74.txt, 60_Alyssa_75.txt, 60_Alyssa_76.txt, 60_Alyssa_77.txt, 60_Ben_40.txt, 60_Ben_44.txt, 60_Ben_45.txt, 60_Ben_46.txt, 60_Ben_47.txt, 60_Ben_49.txt, 60_Ben_50.txt, 60_Ben_53.txt, 60_Ben_56.txt, 60_Ben_60.txt, 60_Ben_61.txt, 60_Ben_63.txt, 60_Ben_71.txt, 60_Ben_72.txt, 60_Ben_73.txt, 60_Ben_78.txt, 60_Ben_79.txt, 70_Alyssa_80.txt, 70_Alyssa_82.txt, 70_Alyssa_83.txt, 70_Alyssa_85.txt, 70_Alyssa_86.txt, 70_Alyssa_89.txt, 70_Ben_81.txt, 70_Ben_84.txt, 70_Ben_87.txt, 70_Ben_88.txt
Case Name Status Exec Time Memory
00_sample_small_00.txt AC 485 ms 22616 KB
00_sample_small_01.txt AC 328 ms 22552 KB
11_small_00.txt AC 327 ms 22540 KB
11_small_01.txt AC 334 ms 22592 KB
11_small_02.txt AC 319 ms 22540 KB
11_small_03.txt AC 325 ms 22512 KB
11_small_04.txt AC 325 ms 22552 KB
11_small_05.txt AC 321 ms 22548 KB
11_small_06.txt AC 327 ms 22508 KB
11_small_07.txt AC 321 ms 22592 KB
11_small_08.txt AC 331 ms 22560 KB
11_small_09.txt AC 329 ms 22500 KB
14_small_10.txt AC 325 ms 22600 KB
14_small_11.txt AC 321 ms 22432 KB
14_small_12.txt AC 321 ms 22528 KB
14_small_13.txt AC 318 ms 22568 KB
14_small_14.txt AC 328 ms 22540 KB
14_small_15.txt AC 325 ms 22536 KB
14_small_16.txt AC 330 ms 22532 KB
14_small_17.txt AC 333 ms 22520 KB
14_small_18.txt AC 338 ms 22552 KB
14_small_19.txt AC 343 ms 22536 KB
14_small_20.txt AC 347 ms 22540 KB
14_small_21.txt AC 331 ms 22520 KB
14_small_22.txt AC 328 ms 22588 KB
14_small_23.txt AC 338 ms 22536 KB
14_small_24.txt AC 350 ms 22676 KB
14_small_25.txt AC 347 ms 22532 KB
14_small_26.txt AC 345 ms 22456 KB
14_small_27.txt AC 354 ms 22524 KB
14_small_28.txt AC 411 ms 22528 KB
14_small_29.txt AC 375 ms 22564 KB
50_random_30.txt AC 358 ms 23212 KB
50_random_31.txt AC 342 ms 22540 KB
50_random_32.txt AC 350 ms 23276 KB
50_random_33.txt AC 495 ms 23140 KB
50_random_34.txt AC 371 ms 22508 KB
50_random_35.txt AC 357 ms 23676 KB
50_random_36.txt AC 361 ms 23188 KB
50_random_37.txt AC 335 ms 23256 KB
50_random_38.txt AC 349 ms 23208 KB
50_random_39.txt AC 335 ms 22552 KB
50_sample_00.txt AC 329 ms 22616 KB
60_Alyssa_41.txt AC 335 ms 22624 KB
60_Alyssa_42.txt AC 347 ms 23176 KB
60_Alyssa_43.txt AC 346 ms 23280 KB
60_Alyssa_48.txt AC 349 ms 24360 KB
60_Alyssa_51.txt AC 329 ms 22500 KB
60_Alyssa_52.txt AC 342 ms 23076 KB
60_Alyssa_54.txt AC 344 ms 22540 KB
60_Alyssa_55.txt AC 332 ms 23332 KB
60_Alyssa_57.txt AC 340 ms 23320 KB
60_Alyssa_58.txt AC 338 ms 23212 KB
60_Alyssa_59.txt AC 335 ms 22536 KB
60_Alyssa_62.txt AC 322 ms 22584 KB
60_Alyssa_64.txt AC 334 ms 23304 KB
60_Alyssa_65.txt AC 327 ms 22600 KB
60_Alyssa_66.txt AC 348 ms 24484 KB
60_Alyssa_67.txt AC 333 ms 23256 KB
60_Alyssa_68.txt AC 338 ms 22592 KB
60_Alyssa_69.txt AC 361 ms 23080 KB
60_Alyssa_70.txt AC 358 ms 23596 KB
60_Alyssa_74.txt AC 373 ms 23324 KB
60_Alyssa_75.txt AC 378 ms 24532 KB
60_Alyssa_76.txt AC 368 ms 23972 KB
60_Alyssa_77.txt AC 389 ms 24384 KB
60_Ben_40.txt AC 360 ms 23260 KB
60_Ben_44.txt AC 343 ms 23300 KB
60_Ben_45.txt AC 334 ms 23232 KB
60_Ben_46.txt AC 350 ms 23312 KB
60_Ben_47.txt AC 361 ms 23372 KB
60_Ben_49.txt AC 345 ms 23184 KB
60_Ben_50.txt AC 342 ms 23296 KB
60_Ben_53.txt AC 327 ms 22540 KB
60_Ben_56.txt AC 332 ms 23276 KB
60_Ben_60.txt AC 325 ms 22548 KB
60_Ben_61.txt AC 354 ms 23028 KB
60_Ben_63.txt AC 346 ms 23820 KB
60_Ben_71.txt AC 366 ms 24800 KB
60_Ben_72.txt AC 345 ms 24512 KB
60_Ben_73.txt AC 329 ms 23324 KB
60_Ben_78.txt AC 326 ms 23224 KB
60_Ben_79.txt AC 344 ms 23516 KB
70_Alyssa_80.txt AC 431 ms 25104 KB
70_Alyssa_82.txt AC 379 ms 24392 KB
70_Alyssa_83.txt AC 339 ms 23992 KB
70_Alyssa_85.txt AC 348 ms 24892 KB
70_Alyssa_86.txt AC 339 ms 23916 KB
70_Alyssa_89.txt AC 344 ms 24008 KB
70_Ben_81.txt AC 345 ms 23224 KB
70_Ben_84.txt AC 363 ms 24956 KB
70_Ben_87.txt AC 347 ms 24852 KB
70_Ben_88.txt AC 356 ms 24012 KB