結果
| 問題 |
No.971 いたずらっ子
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2020-07-03 18:07:20 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 155 ms / 2,000 ms |
| コード長 | 717 bytes |
| コンパイル時間 | 2,906 ms |
| コンパイル使用メモリ | 198,104 KB |
| 最終ジャッジ日時 | 2025-01-11 14:05:28 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, int> PL;
constexpr int INF = 2e9;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
rep(i,h) cin >> s[i];
vector<vector<int>> dp(h, vector<int>(w, INF));
dp[0][0] = 0;
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int cost = 1;
if (s[i][j] == 'k') cost += i + j;
if (i > 0) dp[i][j] = min(dp[i][j], dp[i - 1][j] + cost);
if (j > 0) dp[i][j] = min(dp[i][j], dp[i][j - 1] + cost);
}
}
cout << dp[h - 1][w - 1] << endl;
return 0;
}
iqueue02