結果

問題 No.971 いたずらっ子
ユーザー konchanksukonchanksu
提出日時 2020-04-27 01:16:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 937 ms / 2,000 ms
コード長 895 bytes
コンパイル時間 139 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 267,264 KB
最終ジャッジ日時 2024-04-25 02:14:02
合計ジャッジ時間 9,045 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 937 ms
266,624 KB
testcase_01 AC 937 ms
267,264 KB
testcase_02 AC 710 ms
216,960 KB
testcase_03 AC 826 ms
254,080 KB
testcase_04 AC 749 ms
249,088 KB
testcase_05 AC 823 ms
254,464 KB
testcase_06 AC 647 ms
210,560 KB
testcase_07 AC 74 ms
69,888 KB
testcase_08 AC 262 ms
120,960 KB
testcase_09 AC 233 ms
123,264 KB
testcase_10 AC 75 ms
66,304 KB
testcase_11 AC 40 ms
51,840 KB
testcase_12 AC 40 ms
52,224 KB
testcase_13 AC 58 ms
60,416 KB
testcase_14 AC 89 ms
74,624 KB
testcase_15 AC 51 ms
59,648 KB
testcase_16 AC 52 ms
62,080 KB
testcase_17 AC 37 ms
52,096 KB
testcase_18 AC 37 ms
51,968 KB
testcase_19 AC 37 ms
52,096 KB
testcase_20 AC 35 ms
52,096 KB
testcase_21 AC 36 ms
52,480 KB
testcase_22 AC 35 ms
52,096 KB
testcase_23 AC 36 ms
51,712 KB
testcase_24 AC 37 ms
51,712 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = ['o'.join(input()).split('o') for i in range(H)]
dp = [[0 for i in range(W)] for j in range(H)]

for i in range(1, H + W - 1):
    for j in range(i + 1):
        if i - j >= W or j >= H:
            continue
            
        if j == 0:
            if A[j][i - j] == 'k':
                dp[j][i - j] = dp[j][i - j - 1] + i - j + 1
            else:
                dp[j][i - j] = dp[j][i - j - 1] + 1
                
        elif j == i:
            if A[j][i - j] == 'k':
                dp[j][i - j] = dp[j - 1][i - j] + j + 1
            else:
                dp[j][i - j] = dp[j - 1][i - j] + 1
        
        else:
            if A[j][i - j] == 'k':
                dp[j][i - j] = min(dp[j][i - j - 1], dp[j - 1][i - j]) + i + 1
            else:
                dp[j][i - j] = min(dp[j][i - j - 1], dp[j - 1][i - j]) + 1

print(dp[H - 1][W - 1])
0