結果
問題 | No.971 いたずらっ子 |
ユーザー | utouto97 |
提出日時 | 2020-01-17 23:58:44 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 125 ms / 2,000 ms |
コード長 | 844 bytes |
コンパイル時間 | 1,620 ms |
コンパイル使用メモリ | 164,588 KB |
実行使用メモリ | 42,112 KB |
最終ジャッジ日時 | 2024-11-07 11:35:06 |
合計ジャッジ時間 | 3,476 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 21 |
ソースコード
#include <bits/stdc++.h> using namespace std; #define int long long #define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++) #define all(x) (x).begin(),(x).end() #define sz(x) ((int)x.size()) template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;} template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;} /* */ using vi = vector<int>; using vvi = vector<vi>; using P = pair<int,int>; const int inf = 1LL<<60; signed main() { int h, w; cin >> h >> w; vector<string> a(h); rep(i, 0, h) cin >> a[i]; vvi dp(h, vi(w, inf)); dp[0][0] = 0; rep(i, 0, h) rep(j, 0, w){ if(j+1 < w){ chmin(dp[i][j+1], dp[i][j] + (a[i][j+1] == 'k' ? i+j+2 : 1)); } if(i+1 < h){ chmin(dp[i+1][j], dp[i][j] + (a[i+1][j] == 'k' ? i+j+2 : 1)); } } cout << dp[h-1][w-1] << endl; return 0; }