結果

問題 No.971 いたずらっ子
ユーザー trineutron
提出日時 2020-01-18 03:57:21
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 127 ms / 2,000 ms
コード長 667 bytes
コンパイル時間 1,920 ms
コンパイル使用メモリ 172,364 KB
実行使用メモリ 26,624 KB
最終ジャッジ日時 2024-11-07 11:36:33
合計ジャッジ時間 3,997 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

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