結果
問題 | No.971 いたずらっ子 |
ユーザー |
|
提出日時 | 2020-08-04 04:59:12 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 66 ms / 2,000 ms |
コード長 | 1,232 bytes |
コンパイル時間 | 769 ms |
コンパイル使用メモリ | 82,964 KB |
最終ジャッジ日時 | 2025-01-12 14:12:30 |
ジャッジサーバーID (参考情報) |
judge4 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#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; }