結果

問題 No.971 いたずらっ子
ユーザー trineutrontrineutron
提出日時 2020-01-18 03:57:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 1,628 ms
コンパイル使用メモリ 168,860 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-04-25 02:06:10
合計ジャッジ時間 3,584 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
26,496 KB
testcase_01 AC 116 ms
26,624 KB
testcase_02 AC 87 ms
18,816 KB
testcase_03 AC 105 ms
26,496 KB
testcase_04 AC 98 ms
25,216 KB
testcase_05 AC 107 ms
26,496 KB
testcase_06 AC 79 ms
19,072 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 28 ms
9,472 KB
testcase_09 AC 27 ms
9,472 KB
testcase_10 AC 3 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 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 <bits/stdc++.h>
using namespace std;

int main() {
    const int inf = 1000000000;
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; i++) cin >> a[i];
    vector<vector<int>> cost(h, vector<int>(w, inf));
    cost[0][0] = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int k = (a[i][j] == 'k') ? i + j : 0;
            if (i > 0) {
                cost[i][j] = min(cost[i][j], cost[i - 1][j] + 1 + k);
            }
            if (j > 0) {
                cost[i][j] = min(cost[i][j], cost[i][j - 1] + 1 + k);
            }
        }
    }
    cout << cost[h - 1][w - 1] << endl;
}
0