結果

問題 No.2814 Block Game
ユーザー chineristACchineristAC
提出日時 2024-07-19 23:09:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 453 ms / 2,000 ms
コード長 2,381 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 79,104 KB
最終ジャッジ日時 2024-07-19 23:09:31
合計ジャッジ時間 11,911 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
55,936 KB
testcase_01 AC 407 ms
78,720 KB
testcase_02 AC 426 ms
79,104 KB
testcase_03 AC 427 ms
78,720 KB
testcase_04 AC 420 ms
78,720 KB
testcase_05 AC 428 ms
78,848 KB
testcase_06 AC 429 ms
78,592 KB
testcase_07 AC 430 ms
78,848 KB
testcase_08 AC 409 ms
78,592 KB
testcase_09 AC 453 ms
78,976 KB
testcase_10 AC 409 ms
78,720 KB
testcase_11 AC 429 ms
78,720 KB
testcase_12 AC 448 ms
78,592 KB
testcase_13 AC 417 ms
78,720 KB
testcase_14 AC 413 ms
78,720 KB
testcase_15 AC 424 ms
78,720 KB
testcase_16 AC 418 ms
78,720 KB
testcase_17 AC 427 ms
78,976 KB
testcase_18 AC 411 ms
78,720 KB
testcase_19 AC 418 ms
78,976 KB
testcase_20 AC 446 ms
78,720 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

memo = {}
def calc(a,b,c,d,which,goal,now):
    if (a,b,c,d,which,goal,now) in memo:
        return memo[a,b,c,d,which,goal,now]
    
    assert a+b == c+d
    if a+b == 0:
        if now == goal:
            return "Alice"
        else:
            return "Bob"
    
    res = "Alice" if which == "Bob" else "Bob"
    nxt = "Alice" if which == "Bob" else "Bob"

    if a and c and calc(a-1,b,c-1,d,nxt,goal,now^1) == which:
        res = which
    if a and d and calc(a-1,b,c,d-1,nxt,goal,now) == which:
        res = which
    if b and c and calc(a,b-1,c-1,d,nxt,goal,now) == which:
        res = which
    if b and d and calc(a,b-1,c,d-1,nxt,goal,now) == which:
        res = which
    
    memo[a,b,c,d,which,goal,now] = res
    return res



def solve_even(N):
    p_cnt = 0
    for i in range(100):
        if (N-1)>>i & 1:
            p_cnt += 1
    
    check = N - (1<<p_cnt)
    if check == 0 or check & 1 == 1:
        return "Alice"
    else:
        return "Bob"
    
def solve_odd(N):
    p_cnt = 0
    for i in range(100):
        if (N-1)>>i & 1:
            p_cnt += 1
    
    check = N - (1<<p_cnt)
    if check & 1 == 1:
        return "Alice"
    else:
        return "Bob"
    
def solve(N,S):
    if S == "Even":
        return solve_even(N)
    else:
        return solve_odd(N)
    
def solve_brute(N,S):
    if S == "Even":
        p_cnt = 0
        for i in range(100):
            if (N-1)>>i & 1:
                p_cnt += 1
        a = 1<<p_cnt
        b = N - a
        c = (N+1)//2
        d = N - c
        return calc(a,b,c,d,"Alice",0,0)
    else:
        p_cnt = 0
        for i in range(100):
            if (N-1)>>i & 1:
                p_cnt += 1
        a = 1<<p_cnt
        b = N - a
        c = (N+1)//2
        d = N - c
        return calc(a,b,c,d,"Alice",1,0)
    
#for N in range(3,100):
    #for S in ["Even","Odd"]:
        #print(N,S)
        #assert solve(N,S) == solve_brute(N,S)
    
for _ in range(int(input())):
    N,S = input().split()
    N = int(N)

    if N <= 2:
        print(solve_brute(N,S))
    else:
        print(solve(N,S))
    #print(solve(N,S),solve_brute(N,S))


0