結果

問題 No.971 いたずらっ子
ユーザー cotton_fn_
提出日時 2020-02-02 01:04:33
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,126 bytes
コンパイル時間 1,492 ms
コンパイル使用メモリ 118,952 KB
最終ジャッジ日時 2025-01-08 21:46:44
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T> T iabs(const T& x) { return max(x, -x); }

i64 d[2000][2000];
int main() {
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    for (int i = 0; i < h; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            if (i > 0 || j > 0) {
                d[i][j] = 1ll << 60;
            }
            if (i > 0) {
                d[i][j] = d[i - 1][j] + 1;
            }
            if (j > 0) {
                d[i][j] = min(d[i][j], d[i][j - 1] + 1);
            }
            if (a[i][j] == 'k') {
                d[i][j] += i + j;
            }
        }
    }
    cout << d[h - 1][w - 1] << endl;
    return 0;
}
0