結果

問題 No.2095 High Rise
ユーザー FromBooskaFromBooska
提出日時 2023-06-02 19:12:17
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 289 ms / 2,000 ms
コード長 1,025 bytes
コンパイル時間 274 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 108,696 KB
最終ジャッジ日時 2023-08-28 02:25:07
合計ジャッジ時間 5,486 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,328 KB
testcase_01 AC 70 ms
71,356 KB
testcase_02 AC 72 ms
71,300 KB
testcase_03 AC 72 ms
71,404 KB
testcase_04 AC 70 ms
71,472 KB
testcase_05 AC 72 ms
71,040 KB
testcase_06 AC 72 ms
71,184 KB
testcase_07 AC 72 ms
71,296 KB
testcase_08 AC 72 ms
71,192 KB
testcase_09 AC 72 ms
70,932 KB
testcase_10 AC 73 ms
71,104 KB
testcase_11 AC 72 ms
71,216 KB
testcase_12 AC 84 ms
76,496 KB
testcase_13 AC 87 ms
76,784 KB
testcase_14 AC 86 ms
76,224 KB
testcase_15 AC 83 ms
76,500 KB
testcase_16 AC 83 ms
76,492 KB
testcase_17 AC 111 ms
79,812 KB
testcase_18 AC 104 ms
77,648 KB
testcase_19 AC 88 ms
76,620 KB
testcase_20 AC 114 ms
79,552 KB
testcase_21 AC 138 ms
84,808 KB
testcase_22 AC 289 ms
108,592 KB
testcase_23 AC 285 ms
108,520 KB
testcase_24 AC 284 ms
108,524 KB
testcase_25 AC 282 ms
108,696 KB
testcase_26 AC 285 ms
108,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# グラフ化かdpか
# グラフ化なら各階にダミーを用意して、その階のすべての部屋からコスト0でダミーと行き来できる
# 次の階には有向辺
# ここまで考えて、同じ考えでdpをやった方がおそらくTLEしないと思う
# dp[i階目の][部屋j]までの最低コスト
# 縦移動だけでなく横移動もある、横移動の場合はその階の最小値参照
# 1000*1000ならdpにちょうどいい
# 答えはmin(dp[N])

N, M = map(int, input().split())
A = []
for i in range(N):
    temp = list(map(int, input().split()))
    A.append(temp)

INF = 10**20
dp = [[INF]*M for i in range(N+1)]
for j in range(M):
    dp[0][j] = 0

for i in range(1, N+1):
    # 縦移動
    for j in range(M):
        dp[i][j] = min(dp[i][j], dp[i-1][j] + A[i-1][j])
        
    # 横移動
    mn = min(dp[i])
    for j in range(M):
        dp[i][j] = min(dp[i][j], mn + A[i-1][j])
    
    #print(dp[i])
    
ans = min(dp[N])
if N == 1:
    print(0)
else:
    print(ans)
0