結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-11-06 21:39:13 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 939 bytes |
| コンパイル時間 | 242 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 117,684 KB |
| 最終ジャッジ日時 | 2024-07-22 12:28:32 |
| 合計ジャッジ時間 | 6,508 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 16 WA * 14 |
ソースコード
N,M = map(int,input().split())
cost_s = [[0 for i in range(N)] for j in range(N)]
cost_e = [[0 for i in range(N)] for j in range(N)]
memo = []
for _ in range(M):
h,w,c = map(int,input().split())
cost_s[h-1][w-1] = c
cost_e[h-1][w-1] = c
memo.append((h-1,w-1,c))
for i in range(N):
for j in range(N):
if i==0 and j==0:
continue
tmp = 10**18
if i!=0:
tmp = cost_s[i-1][j] + 1
if j!=0:
tmp = min(cost_s[i][j-1] + 1,tmp)
cost_s[i][j] += tmp
for i in range(N-1,-1,-1):
for j in range(N-1,-1,-1):
if i==N-1 and j==N-1:
continue
tmp = 10**18
if i!=N-1:
tmp = cost_e[i+1][j] + 1
if j!=N-1:
tmp = min(cost_e[i][j+1] + 1,tmp)
cost_e[i][j] += tmp
res = cost_s[N-1][N-1]
for h,w,c in memo:
tmp = cost_s[h][w] + cost_e[h][w] - 2*c
res = min(res,tmp)
print(res)