結果

問題 No.511 落ちゲー 〜手作業のぬくもり〜
ユーザー lam6er
提出日時 2025-04-15 23:31:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 128 ms / 4,000 ms
コード長 1,488 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 81,716 KB
実行使用メモリ 116,336 KB
最終ジャッジ日時 2025-04-15 23:32:41
合計ジャッジ時間 3,867 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 32
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

def main():
    input = sys.stdin.read().split()
    ptr = 0
    n = int(input[ptr]); ptr += 1
    w = int(input[ptr]); ptr += 1
    h = int(input[ptr]); ptr += 1
    
    intervals = deque()
    intervals.append((1, w, 0))
    
    a_score = 0
    b_score = 0
    
    for step in range(n):
        a = int(input[ptr]); ptr += 1
        b = int(input[ptr]); ptr += 1
        x = int(input[ptr]); ptr += 1
        L = x
        R = x + a - 1
        player = 'A' if (step % 2 == 0) else 'B'
        
        new_intervals = deque()
        gain = 0
        
        while intervals:
            s, e, val = intervals.popleft()
            if e < L or s > R:
                new_intervals.append((s, e, val))
                continue
            if s < L:
                new_intervals.append((s, L - 1, val))
            inter_s = max(s, L)
            inter_e = min(e, R)
            new_val = val + b
            if new_val >= h:
                gain += (inter_e - inter_s + 1)
            else:
                new_intervals.append((inter_s, inter_e, new_val))
            if e > R:
                new_intervals.append((R + 1, e, val))
        intervals = new_intervals
        
        if player == 'A':
            a_score += gain
        else:
            b_score += gain
    
    if a_score > b_score:
        print("A")
    elif a_score < b_score:
        print("B")
    else:
        print("DRAW")

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