結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-20 13:54:49 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 42 ms / 2,000 ms |
| コード長 | 773 bytes |
| コンパイル時間 | 1,978 ms |
| コンパイル使用メモリ | 199,320 KB |
| 最終ジャッジ日時 | 2025-01-08 20:17:00 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1 << 30;
signed main() {
ios::sync_with_stdio(false); cin.tie(0);
int h, w;
cin >> h >> w;
vector<string> in(h);
for (int i = 0; i < h; i++) cin >> in[i];
vector<vector<int>> dist(h, vector<int>(w, INF));
dist[0][0] = 0;
for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
if (in[i][j] == 'k') {
if (i > 0) dist[i][j] = min(dist[i][j], dist[i - 1][j] + j + i + 1);
if (j > 0) dist[i][j] = min(dist[i][j], dist[i][j - 1] + j + i + 1);
} else {
if (i > 0) dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1);
if (j > 0) dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1);
}
}
cout << dist[h - 1][w - 1] << '\n';
return 0;
}