結果

問題 No.971 いたずらっ子
ユーザー finefine
提出日時 2020-01-17 21:35:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 914 bytes
コンパイル時間 1,517 ms
コンパイル使用メモリ 169,096 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-25 01:56:16
合計ジャッジ時間 2,990 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
38,784 KB
testcase_01 AC 63 ms
38,784 KB
testcase_02 AC 48 ms
30,080 KB
testcase_03 AC 44 ms
38,912 KB
testcase_04 AC 40 ms
36,864 KB
testcase_05 AC 41 ms
39,040 KB
testcase_06 AC 32 ms
30,976 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 12 ms
12,672 KB
testcase_09 AC 12 ms
12,160 KB
testcase_10 AC 2 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 1 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

constexpr ll INF = 1e18;

int H, W;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> H >> W;
    vector<string> a(H);
    for (int i = 0; i < H; ++i) {
        cin >> a[i];
    }

    vector< vector<ll> > ans(H, vector<ll>(W, INF));
    ans[0][0] = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (i + 1 < H) {
                ll cost = ans[i][j] + 1;
                if (a[i + 1][j] == 'k') cost += i + 1 + j;
                ans[i + 1][j] = min(ans[i + 1][j], cost);
            }

            if (j + 1 < W) {
                ll cost = ans[i][j] + 1;
                if (a[i][j + 1] == 'k') cost += i + 1 + j;
                ans[i][j + 1] = min(ans[i][j + 1], cost);               
            }
        }
    }
    cout << ans[H - 1][W - 1] << "\n";
    return 0;
}
0