結果

問題 No.971 いたずらっ子
ユーザー 👑 KazunKazun
提出日時 2022-01-03 02:38:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 456 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 214 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 175,608 KB
最終ジャッジ日時 2024-04-25 02:18:21
合計ジャッジ時間 5,340 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 455 ms
175,608 KB
testcase_01 AC 456 ms
175,576 KB
testcase_02 AC 365 ms
138,880 KB
testcase_03 AC 308 ms
167,424 KB
testcase_04 AC 304 ms
161,792 KB
testcase_05 AC 313 ms
168,064 KB
testcase_06 AC 261 ms
148,736 KB
testcase_07 AC 76 ms
74,624 KB
testcase_08 AC 131 ms
93,952 KB
testcase_09 AC 130 ms
93,312 KB
testcase_10 AC 55 ms
67,328 KB
testcase_11 AC 39 ms
52,096 KB
testcase_12 AC 35 ms
51,968 KB
testcase_13 AC 47 ms
60,416 KB
testcase_14 AC 88 ms
77,184 KB
testcase_15 AC 42 ms
60,032 KB
testcase_16 AC 40 ms
53,504 KB
testcase_17 AC 37 ms
52,224 KB
testcase_18 AC 36 ms
52,224 KB
testcase_19 AC 36 ms
51,968 KB
testcase_20 AC 35 ms
52,096 KB
testcase_21 AC 36 ms
52,224 KB
testcase_22 AC 35 ms
52,608 KB
testcase_23 AC 34 ms
51,968 KB
testcase_24 AC 36 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#==================================================
H,W=map(int,input().split())

A=[]
for _ in range(H):
    A.append(list(map(lambda x:1 if x=="k" else 0,input()))+[-1])
A.append([-1]*(W+1))

inf=float("inf")
DP=[[inf]*W for _ in range(H)]; DP[0][0]=0

for i in range(H):
    for j in range(W):
        if i!=H-1:
            if A[i+1][j]==0:
                DP[i+1][j]=min(DP[i+1][j],DP[i][j]+1)
            else:
                DP[i+1][j]=min(DP[i+1][j],DP[i][j]+1+((i+1)+j))

        if j!=W-1:
            if A[i][j+1]==0:
                DP[i][j+1]=min(DP[i][j+1],DP[i][j]+1)
            else:
                DP[i][j+1]=min(DP[i][j+1],DP[i][j]+1+(i+(j+1)))

print(DP[-1][-1])
0