結果

問題 No.103 素因数ゲーム リターンズ
ユーザー uafr_csuafr_cs
提出日時 2015-09-11 17:35:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 179 ms / 5,000 ms
コード長 1,437 bytes
コンパイル時間 2,817 ms
コンパイル使用メモリ 77,252 KB
実行使用メモリ 57,816 KB
最終ジャッジ日時 2023-09-26 10:30:39
合計ジャッジ時間 7,648 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 129 ms
55,876 KB
testcase_01 AC 128 ms
56,212 KB
testcase_02 AC 129 ms
55,832 KB
testcase_03 AC 131 ms
55,964 KB
testcase_04 AC 131 ms
55,740 KB
testcase_05 AC 129 ms
56,112 KB
testcase_06 AC 130 ms
55,708 KB
testcase_07 AC 128 ms
55,708 KB
testcase_08 AC 128 ms
56,156 KB
testcase_09 AC 127 ms
55,628 KB
testcase_10 AC 127 ms
55,980 KB
testcase_11 AC 134 ms
55,684 KB
testcase_12 AC 174 ms
57,816 KB
testcase_13 AC 140 ms
56,036 KB
testcase_14 AC 176 ms
57,652 KB
testcase_15 AC 172 ms
57,552 KB
testcase_16 AC 133 ms
55,896 KB
testcase_17 AC 174 ms
57,644 KB
testcase_18 AC 143 ms
56,048 KB
testcase_19 AC 179 ms
57,668 KB
testcase_20 AC 135 ms
56,112 KB
testcase_21 AC 172 ms
57,400 KB
testcase_22 AC 139 ms
56,168 KB
testcase_23 AC 140 ms
55,956 KB
testcase_24 AC 140 ms
56,196 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.Set;
import java.util.TreeSet;

public class Main {

	public static int grundy(int n, LinkedList<Integer> primes, int[] memo){
		if(memo[n] >= 0){ return memo[n]; }
		if(n == 1){ return memo[n] = 0; }
		
		TreeSet<Integer> set = new TreeSet<Integer>();
		
		for(final int prime : primes){
			if(n < prime){ break; }
			
			if(n % prime == 0){
				set.add(grundy(n / prime, primes, memo));
				
				if((n / prime) % prime == 0){
					set.add(grundy(n / (prime * prime), primes, memo));
				}
			}
		}
		
		for(int i = 0; ; i++){
			if(!set.contains(i)){
				return memo[n] = i;
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final int MAX = 10000;
		int[] memo = new int[MAX + 1];
		Arrays.fill(memo, -1);
		
		LinkedList<Integer> primes = new LinkedList<Integer>();
		boolean[] is_prime = new boolean[MAX + 1];
		Arrays.fill(is_prime, true);
		is_prime[0] = is_prime[1] = false;
		
		for(int i = 2; i <= MAX; i++){
			if(is_prime[i]){
				primes.add(i);
				
				for(int j = i * 2; j <= MAX; j += i){
					is_prime[j] = false;
				}
			}
		}
		
		int grundy_number = 0;
		for(int i = 0; i < N; i++){
			grundy_number ^= grundy(sc.nextInt(), primes, memo);
		}
		
		System.out.println(grundy_number == 0 ? "Bob" : "Alice");
		
	}

}
0