結果

問題 No.971 いたずらっ子
ユーザー 👑 KazunKazun
提出日時 2022-01-03 02:43:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 374 ms / 2,000 ms
コード長 612 bytes
コンパイル時間 211 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 165,120 KB
最終ジャッジ日時 2024-04-25 02:18:41
合計ジャッジ時間 4,859 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 374 ms
159,744 KB
testcase_01 AC 372 ms
158,976 KB
testcase_02 AC 306 ms
129,280 KB
testcase_03 AC 296 ms
164,480 KB
testcase_04 AC 280 ms
155,392 KB
testcase_05 AC 289 ms
165,120 KB
testcase_06 AC 233 ms
131,968 KB
testcase_07 AC 68 ms
67,712 KB
testcase_08 AC 125 ms
88,320 KB
testcase_09 AC 120 ms
89,856 KB
testcase_10 AC 54 ms
63,872 KB
testcase_11 AC 40 ms
51,968 KB
testcase_12 AC 40 ms
51,968 KB
testcase_13 AC 50 ms
59,904 KB
testcase_14 AC 96 ms
76,800 KB
testcase_15 AC 47 ms
59,648 KB
testcase_16 AC 44 ms
53,248 KB
testcase_17 AC 40 ms
51,584 KB
testcase_18 AC 40 ms
51,968 KB
testcase_19 AC 39 ms
51,840 KB
testcase_20 AC 40 ms
52,096 KB
testcase_21 AC 41 ms
52,096 KB
testcase_22 AC 40 ms
52,352 KB
testcase_23 AC 39 ms
51,712 KB
testcase_24 AC 41 ms
51,712 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())))

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

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

        if j!=0:
            if a[j]==0:
                D[j]=min(D[j],D[j-1]+1)
            else:
                D[j]=min(D[j],D[j-1]+1+(i+j))

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