結果

問題 No.971 いたずらっ子
ユーザー 👑 KazunKazun
提出日時 2022-01-03 02:46:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 786 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 141,696 KB
最終ジャッジ日時 2024-04-20 13:30:32
合計ジャッジ時間 4,732 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 218 ms
123,136 KB
testcase_06 AC 184 ms
112,492 KB
testcase_07 AC 61 ms
67,584 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 50 ms
63,488 KB
testcase_11 AC 36 ms
51,968 KB
testcase_12 AC 35 ms
52,352 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 38 ms
51,968 KB
testcase_18 AC 37 ms
52,480 KB
testcase_19 AC 36 ms
52,224 KB
testcase_20 AC 36 ms
51,968 KB
testcase_21 AC 38 ms
52,480 KB
testcase_22 AC 37 ms
52,608 KB
testcase_23 AC 39 ms
52,096 KB
testcase_24 AC 36 ms
52,736 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=100*(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