結果

問題 No.971 いたずらっ子
ユーザー utouto97utouto97
提出日時 2020-01-17 23:58:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 144 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 149,792 KB
実行使用メモリ 42,348 KB
最終ジャッジ日時 2023-08-07 07:58:22
合計ジャッジ時間 3,764 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 144 ms
41,848 KB
testcase_01 AC 144 ms
41,860 KB
testcase_02 AC 107 ms
30,560 KB
testcase_03 AC 112 ms
41,900 KB
testcase_04 AC 106 ms
39,748 KB
testcase_05 AC 111 ms
42,348 KB
testcase_06 AC 84 ms
30,712 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 31 ms
13,396 KB
testcase_09 AC 29 ms
12,816 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}

0