結果

問題 No.2330 Eat Slime
ユーザー gew1fw
提出日時 2025-06-12 20:52:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,557 bytes
コンパイル時間 192 ms
コンパイル使用メモリ 82,052 KB
実行使用メモリ 250,352 KB
最終ジャッジ日時 2025-06-12 20:57:04
合計ジャッジ時間 6,721 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    idx = 0
    N = int(data[idx])
    idx +=1
    M = int(data[idx])
    idx +=1
    X = int(data[idx])
    idx +=1

    C = list(map(int, data[idx:idx+N]))
    idx +=N

    # Preprocess: for each color c, store the positions in a sorted list
    color_positions = {c: [] for c in range(1,6)}
    for i in range(N):
        c = C[i]
        color_positions[c].append(i+1)  # since positions are 1-based

    # Precompute sum_ac: sum_ac[a][c] is sum of Y_j for all j where A_j = a, B_j = c
    sum_ac = [[0]*6 for _ in range(N+2)]  # a can be up to N
    for _ in range(M):
        A_j = int(data[idx])
        idx +=1
        B_j = int(data[idx])
        idx +=1
        Y_j = int(data[idx])
        idx +=1
        sum_ac[A_j][B_j] += Y_j

    additional_points = [0]*(N+2)  # k can be up to N

    for c in range(1,6):
        positions = color_positions[c]
        len_pos = len(positions)
        for a in range(1, N+1):
            if sum_ac[a][c] == 0:
                continue
            # Find the first s in positions where s >= a
            idx_pos = bisect.bisect_left(positions, a)
            for s in positions[idx_pos:]:
                k = s - a
                if k <= N:
                    additional_points[k] += sum_ac[a][c]

    max_total = 0
    for k in range(0, N+1):
        total = k * X + additional_points[k]
        if total > max_total:
            max_total = total

    print(max_total)

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