結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-01-17 21:35:28 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 71 ms / 2,000 ms |
| コード長 | 914 bytes |
| コンパイル時間 | 1,755 ms |
| コンパイル使用メモリ | 172,808 KB |
| 実行使用メモリ | 38,912 KB |
| 最終ジャッジ日時 | 2024-11-07 11:24:32 |
| 合計ジャッジ時間 | 3,381 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#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;
}