結果

問題 No.2095 High Rise
ユーザー FromBooskaFromBooska
提出日時 2023-06-02 19:09:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 302 ms / 2,000 ms
コード長 913 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,124 KB
実行使用メモリ 108,560 KB
最終ジャッジ日時 2023-08-28 02:25:01
合計ジャッジ時間 7,648 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,284 KB
testcase_01 AC 76 ms
71,204 KB
testcase_02 AC 73 ms
71,084 KB
testcase_03 AC 76 ms
71,072 KB
testcase_04 AC 70 ms
71,392 KB
testcase_05 AC 71 ms
71,476 KB
testcase_06 AC 77 ms
71,240 KB
testcase_07 AC 71 ms
71,296 KB
testcase_08 AC 70 ms
71,080 KB
testcase_09 AC 71 ms
71,416 KB
testcase_10 AC 71 ms
71,392 KB
testcase_11 AC 71 ms
71,180 KB
testcase_12 AC 110 ms
76,252 KB
testcase_13 AC 86 ms
76,572 KB
testcase_14 AC 84 ms
76,512 KB
testcase_15 AC 83 ms
76,540 KB
testcase_16 AC 85 ms
76,480 KB
testcase_17 AC 113 ms
80,052 KB
testcase_18 AC 108 ms
77,656 KB
testcase_19 AC 88 ms
76,492 KB
testcase_20 AC 117 ms
79,348 KB
testcase_21 AC 136 ms
85,032 KB
testcase_22 AC 302 ms
108,412 KB
testcase_23 AC 299 ms
108,504 KB
testcase_24 AC 287 ms
108,560 KB
testcase_25 AC 286 ms
108,560 KB
testcase_26 AC 287 ms
108,524 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)
    
#print(A)

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