結果
問題 |
No.1297 銅像
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:31:00 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,248 bytes |
コンパイル時間 | 322 ms |
コンパイル使用メモリ | 82,208 KB |
実行使用メモリ | 93,920 KB |
最終ジャッジ日時 | 2025-03-31 17:31:50 |
合計ジャッジ時間 | 5,917 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 4 WA * 3 TLE * 1 -- * 13 |
ソースコード
import sys def main(): import sys N, C = map(int, sys.stdin.readline().split()) ab = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)] a = [x[0] for x in ab] b = [x[1] for x in ab] # Calculate the cost if all statues are built by craftsman i min_all = float('inf') for i in range(N): total = b[i] + a[i] * N sum_dist = 0 for j in range(N): sum_dist += abs(i - j) total += sum_dist * C if total < min_all: min_all = total # Initialize DP with the minimum of single craftsman dp = [float('inf')] * (N + 1) dp[0] = 0 for r in range(1, N+1): for l in range(r-1, max(r-4, -1), -1): current_min = float('inf') for k in range(l, r): cost = b[k] + a[k] * (r - l) sum_d = 0 for x in range(l+1, r+1): sum_d += abs(k + 1 - x) cost += sum_d * C if dp[l] + cost < current_min: current_min = dp[l] + cost if current_min < dp[r]: dp[r] = current_min result = min(min_all, dp[N]) print(result) if __name__ == "__main__": main()