結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 364 ms
140,800 KB
testcase_01 AC 350 ms
140,800 KB
testcase_02 AC 308 ms
126,080 KB
testcase_03 AC 257 ms
123,136 KB
testcase_04 AC 258 ms
136,320 KB
testcase_05 AC 247 ms
123,392 KB
testcase_06 AC 211 ms
112,768 KB
testcase_07 AC 69 ms
67,712 KB
testcase_08 AC 121 ms
88,320 KB
testcase_09 AC 121 ms
90,112 KB
testcase_10 AC 56 ms
63,616 KB
testcase_11 AC 41 ms
52,352 KB
testcase_12 AC 40 ms
52,224 KB
testcase_13 AC 49 ms
59,648 KB
testcase_14 AC 97 ms
76,800 KB
testcase_15 AC 48 ms
59,776 KB
testcase_16 AC 46 ms
53,376 KB
testcase_17 AC 41 ms
52,224 KB
testcase_18 AC 41 ms
51,968 KB
testcase_19 AC 41 ms
51,840 KB
testcase_20 AC 40 ms
51,840 KB
testcase_21 AC 41 ms
52,224 KB
testcase_22 AC 40 ms
51,968 KB
testcase_23 AC 40 ms
51,968 KB
testcase_24 AC 40 ms
51,840 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())))

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

for i in range(H):
    a=A[i]
    D=DP[i]
    for j in range(W):
        if i==j==0:
            continue

        X=inf
        if i!=0:
            if a[j]==0:
                if X>DP[i-1][j]+1:
                    X=DP[i-1][j]+1
            else:
                if X>DP[i-1][j]+1+(i+j):
                    X=DP[i-1][j]+1+(i+j)

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

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