結果

問題 No.971 いたずらっ子
ユーザー face4face4
提出日時 2020-01-17 21:35:05
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 214 ms / 2,000 ms
コード長 706 bytes
コンパイル時間 706 ms
コンパイル使用メモリ 72,576 KB
実行使用メモリ 22,980 KB
最終ジャッジ日時 2024-04-25 01:56:08
合計ジャッジ時間 3,761 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
22,784 KB
testcase_01 AC 206 ms
22,784 KB
testcase_02 AC 158 ms
18,176 KB
testcase_03 AC 214 ms
22,980 KB
testcase_04 AC 195 ms
21,664 KB
testcase_05 AC 209 ms
22,784 KB
testcase_06 AC 160 ms
18,432 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 55 ms
8,320 KB
testcase_09 AC 52 ms
8,576 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 1 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> dp(h, vector<int>(w, 1<<30));
    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }
    dp[0][0] = 0;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i+1 < h){
                dp[i+1][j] = min(dp[i+1][j], (mat[i+1][j]=='k' ? i+j+1 : 0) + dp[i][j] + 1);
            }
            if(j+1 < w){
                dp[i][j+1] = min(dp[i][j+1], (mat[i][j+1]=='k' ? i+j+1 : 0) + dp[i][j] + 1);
            }
        }
    }
    cout << dp[h-1][w-1] << endl;
    return 0;
}
0