結果

問題 No.259 セグメントフィッシング+
ユーザー gew1fw
提出日時 2025-06-12 18:14:40
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,562 bytes
コンパイル時間 132 ms
コンパイル使用メモリ 82,124 KB
実行使用メモリ 122,272 KB
最終ジャッジ日時 2025-06-12 18:15:28
合計ジャッジ時間 4,830 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 5 TLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

def compute_left_pos(y0, delta, N):
    effective = y0 - delta
    if effective >= 0:
        return effective
    else:
        effective = -effective - 1
        cycles = effective // N
        remainder = effective % N
        if cycles % 2 == 0:
            return remainder
        else:
            return (N - 1) - remainder

def compute_right_pos(y0, delta, N):
    effective = y0 + delta
    cycles = effective // N
    remainder = effective % N
    if cycles % 2 == 0:
        return remainder
    else:
        return (N - 1) - remainder

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1
    Q = int(input[ptr])
    ptr += 1

    fish = []
    for _ in range(Q):
        cmd = input[ptr]
        ptr += 1
        t = int(input[ptr])
        ptr += 1
        y = int(input[ptr])
        ptr += 1
        z = int(input[ptr])
        ptr += 1

        if cmd == 'L' or cmd == 'R':
            fish.append((t, y, cmd, z))
        elif cmd == 'C':
            a = y
            b = z
            current_t = t
            total = 0
            for (t0, y0, direction, z_val) in fish:
                if t0 > current_t:
                    continue
                delta = current_t - t0
                if direction == 'L':
                    pos = compute_left_pos(y0, delta, N)
                else:
                    pos = compute_right_pos(y0, delta, N)
                if a <= pos < b:
                    total += z_val
            print(total)

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