結果

問題 No.2330 Eat Slime
ユーザー gew1fw
提出日時 2025-06-12 20:57:48
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,144 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 81,800 KB
実行使用メモリ 121,472 KB
最終ジャッジ日時 2025-06-12 21:01:25
合計ジャッジ時間 7,262 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 TLE * 1 -- * 24
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    N, M, X = map(int, sys.stdin.readline().split())
    C = list(map(int, sys.stdin.readline().split()))
    
    sum_y = defaultdict(dict)
    for _ in range(M):
        A, B, Y = map(int, sys.stdin.readline().split())
        if B not in sum_y[A]:
            sum_y[A][B] = 0
        sum_y[A][B] += Y
    
    # Build color_to_a
    color_to_a = defaultdict(list)
    for a in sum_y:
        for c in sum_y[a]:
            if sum_y[a][c] > 0:
                color_to_a[c].append(a)
    
    delta = [0] * (N + 2)  # k can be 0 to N
    
    for i in range(1, N + 1):
        c = C[i - 1]
        if c not in color_to_a:
            continue
        for a in color_to_a[c]:
            if a > i:
                continue
            k = i - a
            if k < 0:
                continue
            # 避免重复访问sum_y,直接计算
            delta[k] += sum_y[a][c]
    
    max_score = 0
    for k in range(N + 1):
        score = k * X + delta[k]
        if score > max_score:
            max_score = score
    print(max_score)

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