Submission #552407


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 < 30;d++){
			int p = 0;
			for(int i = 0;i < n-1;i++){
				if(((a[i]^a[i+1])>>>d) == 0){
					i++;
					nim ^= (Integer.reverse(a[i]^a[i+1])>>>2)-1;
				}else{
					a[p++] = a[i];
				}
			}
			n = p;
		}
		if(n > 0)nim ^= (Integer.reverse(a[0])>>>2) - 1;
		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 4673 Byte
Status AC
Exec Time 452 ms
Memory 25404 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 372 ms 23016 KB
00_sample_small_01.txt AC 366 ms 22896 KB
11_small_00.txt AC 361 ms 22836 KB
11_small_01.txt AC 367 ms 22852 KB
11_small_02.txt AC 357 ms 22892 KB
11_small_03.txt AC 369 ms 22828 KB
11_small_04.txt AC 360 ms 22884 KB
11_small_05.txt AC 363 ms 22972 KB
11_small_06.txt AC 363 ms 22788 KB
11_small_07.txt AC 363 ms 22880 KB
11_small_08.txt AC 358 ms 22848 KB
11_small_09.txt AC 357 ms 22872 KB
14_small_10.txt AC 364 ms 22856 KB
14_small_11.txt AC 370 ms 22880 KB
14_small_12.txt AC 360 ms 22788 KB
14_small_13.txt AC 359 ms 22880 KB
14_small_14.txt AC 364 ms 22832 KB
14_small_15.txt AC 363 ms 22856 KB
14_small_16.txt AC 365 ms 22764 KB
14_small_17.txt AC 355 ms 22864 KB
14_small_18.txt AC 356 ms 22776 KB
14_small_19.txt AC 353 ms 22668 KB
14_small_20.txt AC 359 ms 22756 KB
14_small_21.txt AC 373 ms 22664 KB
14_small_22.txt AC 360 ms 22780 KB
14_small_23.txt AC 384 ms 22804 KB
14_small_24.txt AC 378 ms 22788 KB
14_small_25.txt AC 380 ms 22832 KB
14_small_26.txt AC 359 ms 22844 KB
14_small_27.txt AC 382 ms 22876 KB
14_small_28.txt AC 355 ms 22856 KB
14_small_29.txt AC 383 ms 22820 KB
50_random_30.txt AC 409 ms 24484 KB
50_random_31.txt AC 382 ms 23820 KB
50_random_32.txt AC 417 ms 25092 KB
50_random_33.txt AC 404 ms 24344 KB
50_random_34.txt AC 355 ms 22764 KB
50_random_35.txt AC 408 ms 24504 KB
50_random_36.txt AC 404 ms 24596 KB
50_random_37.txt AC 411 ms 25072 KB
50_random_38.txt AC 405 ms 24332 KB
50_random_39.txt AC 387 ms 24272 KB
50_sample_00.txt AC 353 ms 22700 KB
60_Alyssa_41.txt AC 390 ms 23388 KB
60_Alyssa_42.txt AC 403 ms 24224 KB
60_Alyssa_43.txt AC 410 ms 24320 KB
60_Alyssa_48.txt AC 419 ms 25104 KB
60_Alyssa_51.txt AC 380 ms 23412 KB
60_Alyssa_52.txt AC 405 ms 24300 KB
60_Alyssa_54.txt AC 375 ms 23816 KB
60_Alyssa_55.txt AC 395 ms 24588 KB
60_Alyssa_57.txt AC 407 ms 24536 KB
60_Alyssa_58.txt AC 396 ms 24388 KB
60_Alyssa_59.txt AC 386 ms 23452 KB
60_Alyssa_62.txt AC 385 ms 22832 KB
60_Alyssa_64.txt AC 386 ms 24340 KB
60_Alyssa_65.txt AC 363 ms 23304 KB
60_Alyssa_66.txt AC 404 ms 25140 KB
60_Alyssa_67.txt AC 392 ms 24332 KB
60_Alyssa_68.txt AC 376 ms 23824 KB
60_Alyssa_69.txt AC 407 ms 24236 KB
60_Alyssa_70.txt AC 407 ms 24860 KB
60_Alyssa_74.txt AC 406 ms 25228 KB
60_Alyssa_75.txt AC 403 ms 24936 KB
60_Alyssa_76.txt AC 397 ms 25196 KB
60_Alyssa_77.txt AC 392 ms 24928 KB
60_Ben_40.txt AC 420 ms 25008 KB
60_Ben_44.txt AC 410 ms 24368 KB
60_Ben_45.txt AC 408 ms 24584 KB
60_Ben_46.txt AC 397 ms 24444 KB
60_Ben_47.txt AC 418 ms 24540 KB
60_Ben_49.txt AC 421 ms 24316 KB
60_Ben_50.txt AC 410 ms 24564 KB
60_Ben_53.txt AC 398 ms 24096 KB
60_Ben_56.txt AC 425 ms 25152 KB
60_Ben_60.txt AC 374 ms 23432 KB
60_Ben_61.txt AC 382 ms 24240 KB
60_Ben_63.txt AC 395 ms 24592 KB
60_Ben_71.txt AC 422 ms 25132 KB
60_Ben_72.txt AC 426 ms 25152 KB
60_Ben_73.txt AC 406 ms 24624 KB
60_Ben_78.txt AC 419 ms 25180 KB
60_Ben_79.txt AC 410 ms 24508 KB
70_Alyssa_80.txt AC 438 ms 24988 KB
70_Alyssa_82.txt AC 438 ms 25404 KB
70_Alyssa_83.txt AC 436 ms 25172 KB
70_Alyssa_85.txt AC 416 ms 24948 KB
70_Alyssa_86.txt AC 415 ms 25232 KB
70_Alyssa_89.txt AC 452 ms 25000 KB
70_Ben_81.txt AC 405 ms 24396 KB
70_Ben_84.txt AC 413 ms 25008 KB
70_Ben_87.txt AC 440 ms 24932 KB
70_Ben_88.txt AC 415 ms 25216 KB