結果
問題 |
No.2330 Eat Slime
|
ユーザー |
![]() |
提出日時 | 2025-06-12 18:20:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,484 bytes |
コンパイル時間 | 160 ms |
コンパイル使用メモリ | 82,524 KB |
実行使用メモリ | 56,128 KB |
最終ジャッジ日時 | 2025-06-12 18:21:15 |
合計ジャッジ時間 | 7,272 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 TLE * 1 -- * 24 |
ソースコード
import bisect from collections import defaultdict 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 color_pos = defaultdict(list) for i in range(N): color_pos[C[i]].append(i + 1) # Positions are 1-based sum_ya_c = defaultdict(lambda: defaultdict(int)) 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_ya_c[A_j][B_j] += Y_j contrib = [0] * (N + 1) # contrib[K] for K from 0 to N for a in sum_ya_c: for c in sum_ya_c[a]: if c not in color_pos: continue pos_list = color_pos[c] # Find the first position >= a idx_pos = bisect.bisect_left(pos_list, a) for pos in pos_list[idx_pos:]: if pos > N: break # Just in case, though pos is <=N as per input K = pos - a if K <= N: contrib[K] += sum_ya_c[a][c] max_total = 0 for K in range(0, N + 1): current_total = X * K + contrib[K] if current_total > max_total: max_total = current_total print(max_total) if __name__ == "__main__": main()