結果

問題 No.1208 anti primenumber game
ユーザー lam6er
提出日時 2025-03-20 20:45:00
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,473 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 123,836 KB
最終ジャッジ日時 2025-03-20 20:45:16
合計ジャッジ時間 7,148 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 31 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

def is_prime(n):
    if n < 2:
        return False
    for i in range(2, int(n**0.5) + 1):
        if n % i == 0:
            return False
    return True

def get_max_score(A, M):
    r_candidates = [0, 1, 4, 6, 8, 9, 10, 12, 14, 15, 16, 18, 20, 21, 22, 24, 25, 26, 27, 28, 30]
    max_s = -float('inf')
    for r in r_candidates:
        if r > A:
            continue
        x = A - r
        if x < 1:
            continue
        remainder = r
        if remainder == 0:
            s = x - M
        else:
            s = x
        if s > max_s:
            max_s = s
    return max_s

def main():
    input = sys.stdin.read().split()
    idx = 0
    N = int(input[idx]); idx +=1
    M = int(input[idx]); idx +=1
    A_list = list(map(int, input[idx:idx+N]))
    
    # Initialize DP variables. Since we process from right to left,
    # we only need to keep track of the next state.
    dp_prev_a = 0  # dp[i+1][0]
    dp_prev_b = 0  # dp[i+1][1]
    
    for i in reversed(range(N)):
        A = A_list[i]
        s_max = get_max_score(A, M)
        
        # Update current dp values
        current_a = s_max + dp_prev_b
        current_b = -s_max + dp_prev_a
        
        dp_prev_a, dp_prev_b = current_a, current_b
    
    total_diff = dp_prev_a  # dp[0][0] is the first player's score diff after processing all piles
    
    if total_diff > 0:
        print("First")
    else:
        print("Second")

if __name__ == "__main__":
    main()
0