結果
| 問題 |
No.1818 6 Operations
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 15:14:37 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,258 bytes |
| コンパイル時間 | 240 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 68,096 KB |
| 最終ジャッジ日時 | 2025-06-12 15:14:45 |
| 合計ジャッジ時間 | 2,402 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 3 |
| other | WA * 30 |
ソースコード
import sys
def main():
sys.setrecursionlimit(1 << 25)
N, M = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
prefixA = [0] * (N + 1)
for i in range(1, N+1):
prefixA[i] = prefixA[i-1] + A[i-1]
prefixB = [0] * (M + 1)
for i in range(1, M+1):
prefixB[i] = prefixB[i-1] + B[i-1]
INF = float('inf')
dp = [[INF] * (M+1) for _ in range(N+1)]
dp[0][0] = 0
for i in range(N+1):
for j in range(M+1):
if i == 0 and j == 0:
dp[i][j] = 0
continue
if dp[i][j] == INF:
continue
# Try adding an operation to merge A
if i > 1:
for k in range(1, i):
new_sum = prefixA[i] - prefixA[k]
cost = 1 + abs(new_sum - (prefixB[j] - prefixB[j]))
if dp[i][j] + cost < dp[k][j]:
dp[k][j] = dp[i][j] + cost
# Similarly, try to split or other operations
# This is a placeholder for the actual DP transitions
print(dp[N][M])
if __name__ == "__main__":
main()
gew1fw