結果

問題 No.971 いたずらっ子
ユーザー kimiyukikimiyuki
提出日時 2020-01-18 01:25:08
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 122 ms / 2,000 ms
コード長 1,068 bytes
コンパイル時間 2,040 ms
コンパイル使用メモリ 204,724 KB
実行使用メモリ 41,904 KB
最終ジャッジ日時 2023-08-07 07:59:31
合計ジャッジ時間 4,119 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
41,844 KB
testcase_01 AC 122 ms
41,904 KB
testcase_02 AC 90 ms
30,512 KB
testcase_03 AC 116 ms
41,896 KB
testcase_04 AC 110 ms
39,980 KB
testcase_05 AC 110 ms
41,808 KB
testcase_06 AC 83 ms
30,820 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 32 ms
13,348 KB
testcase_09 AC 30 ms
12,772 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
using namespace std;
template <class T, class U> inline void chmin(T & a, U const & b) { a = min<T>(a, b); }
template <typename X, typename T> auto make_table(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto make_table(X x, Y y, Z z, Zs... zs) { auto cont = make_table(y, z, zs...); return vector<decltype(cont)>(x, cont); }
template <typename T> istream & operator >> (istream & in, vector<T> & xs) { REP (i, xs.size()) { in >> xs[i]; } return in; }

int64_t solve(int h, int w, const vector<string> & f) {
    auto dp = make_table(h, w, INT64_MAX);
    dp[0][0] = 0;
    REP (y, h) REP (x, w) {
        if (y - 1 >= 0) chmin(dp[y][x], dp[y - 1][x] + 1);
        if (x - 1 >= 0) chmin(dp[y][x], dp[y][x - 1] + 1);
        if (f[y][x] == 'k') dp[y][x] += y + x;
    }
    return dp[h - 1][w - 1];
}

int main() {
    int h, w; cin >> h >> w;
    vector<string> f(h); cin >> f;
    cout << solve(h, w, f) << endl;
    return 0;
}
0