結果

問題 No.971 いたずらっ子
ユーザー MisterMister
提出日時 2020-08-04 04:59:12
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 1,232 bytes
コンパイル時間 799 ms
コンパイル使用メモリ 87,272 KB
実行使用メモリ 39,040 KB
最終ジャッジ日時 2024-04-25 02:14:53
合計ジャッジ時間 2,349 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
38,912 KB
testcase_01 AC 59 ms
38,912 KB
testcase_02 AC 44 ms
30,080 KB
testcase_03 AC 47 ms
39,040 KB
testcase_04 AC 46 ms
36,736 KB
testcase_05 AC 45 ms
38,912 KB
testcase_06 AC 35 ms
31,104 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 14 ms
12,672 KB
testcase_09 AC 13 ms
12,160 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

constexpr int INF = 1 << 30;

void solve() {
    int h, w;
    std::cin >> h >> w;

    std::vector<std::string> grid(h);
    for (auto& s : grid) std::cin >> s;

    auto dist = vec(h, vec(w, INF));
    auto sdist = vec(h, vec(w, INF));
    dist[0][0] = sdist[0][0] = 0;

    for (int x = 0; x < h; ++x) {
        for (int y = 0; y < w; ++y) {
            if (x > 0) {
                dist[x][y] = std::min(dist[x][y], dist[x - 1][y] + 1);
                sdist[x][y] = std::min(sdist[x][y], sdist[x - 1][y] + 1);
            }
            if (y > 0) {
                dist[x][y] = std::min(dist[x][y], dist[x][y - 1] + 1);
                sdist[x][y] = std::min(sdist[x][y], sdist[x][y - 1] + 1);
            }

            if (grid[x][y] == 'k') dist[x][y] += sdist[x][y];
        }
    }

    std::cout << dist[h - 1][w - 1] << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0