結果
問題 |
No.2330 Eat Slime
|
ユーザー |
![]() |
提出日時 | 2025-04-16 15:30:57 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,812 bytes |
コンパイル時間 | 170 ms |
コンパイル使用メモリ | 82,004 KB |
実行使用メモリ | 52,096 KB |
最終ジャッジ日時 | 2025-04-16 15:34:45 |
合計ジャッジ時間 | 7,236 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 5 TLE * 1 -- * 24 |
ソースコード
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 # Convert to 1-based indexing C = [0] + C # Now C[1] is the first element # Preprocess positions for each color (1-5) pos_by_color = [[] for _ in range(6)] # colors 0-5 (0 unused) for pos in range(1, N+1): c = C[pos] pos_by_color[c].append(pos) # Read all M conditions and group by (A_j, B_j) sum_ab = {} 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 key = (A_j, B_j) if key not in sum_ab: sum_ab[key] = 0 sum_ab[key] += Y_j # Initialize sum_Y for each possible k (0 to N) sum_Y = [0] * (N + 1) # Process each (a, b) pair in sum_ab for (a, b), total in sum_ab.items(): if a > N: continue # No possible positions pos_list = pos_by_color[b] if not pos_list: continue # No positions for this color # Find the first position >= a using bisect idx_pos = bisect.bisect_left(pos_list, a) # Iterate from idx_pos to end of pos_list for pos in pos_list[idx_pos:]: k = pos - a if k <= N: # Since pos <= N and a >=1, k can be up to N-1 sum_Y[k] += total # Compute the maximum score max_score = 0 for k in range(N + 1): current = X * k + sum_Y[k] if current > max_score: max_score = current print(max_score) if __name__ == "__main__": main()