結果

問題 No.971 いたずらっ子
ユーザー 👑 emthrmemthrm
提出日時 2020-01-18 01:44:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 59 ms / 2,000 ms
コード長 1,423 bytes
コンパイル時間 2,145 ms
コンパイル使用メモリ 205,456 KB
実行使用メモリ 38,752 KB
最終ジャッジ日時 2023-08-07 07:59:35
合計ジャッジ時間 3,606 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 58 ms
38,720 KB
testcase_01 AC 59 ms
38,752 KB
testcase_02 AC 44 ms
29,716 KB
testcase_03 AC 45 ms
38,628 KB
testcase_04 AC 42 ms
36,532 KB
testcase_05 AC 45 ms
38,640 KB
testcase_06 AC 36 ms
30,724 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 13 ms
12,612 KB
testcase_09 AC 12 ms
11,972 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
// const int dy[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int h, w; cin >> h >> w;
  vector<string> a(h); REP(i, h) cin >> a[i];
  vector<vector<ll> > dp(h, vector<ll>(w, LINF));
  dp[0][0] = 0;
  REP(i, h) REP(j, w) {
    if (i - 1 >= 0) chmin(dp[i][j], dp[i - 1][j] + 1 + (i + j) * (a[i][j] == 'k'));
    if (j - 1 >= 0) chmin(dp[i][j], dp[i][j - 1] + 1 + (i + j) * (a[i][j] == 'k'));
  }
  cout << dp[h - 1][w - 1] << '\n';
  return 0;
}
0