結果

問題 No.971 いたずらっ子
ユーザー MayimgMayimg
提出日時 2020-01-20 13:54:49
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 2,149 ms
コンパイル使用メモリ 203,624 KB
実行使用メモリ 23,156 KB
最終ジャッジ日時 2023-08-07 08:03:18
合計ジャッジ時間 3,722 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
23,156 KB
testcase_01 AC 42 ms
23,132 KB
testcase_02 AC 32 ms
18,144 KB
testcase_03 AC 34 ms
23,144 KB
testcase_04 AC 33 ms
21,768 KB
testcase_05 AC 31 ms
23,100 KB
testcase_06 AC 24 ms
18,616 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 10 ms
8,356 KB
testcase_09 AC 9 ms
8,036 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,384 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 1 ms
4,384 KB
testcase_18 AC 2 ms
4,384 KB
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
constexpr int INF = 1 << 30;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int h, w;
  cin >> h >> w;
  vector<string> in(h);
  for (int i = 0; i < h; i++) cin >> in[i];
  vector<vector<int>> dist(h, vector<int>(w, INF));
  dist[0][0] = 0;
  for (int i = 0; i < h; i++) for (int j = 0; j < w; j++) {
    if (in[i][j] == 'k') {
      if (i > 0) dist[i][j] = min(dist[i][j], dist[i - 1][j] + j + i + 1);
      if (j > 0) dist[i][j] = min(dist[i][j], dist[i][j - 1] + j + i + 1);
    } else {
      if (i > 0) dist[i][j] = min(dist[i][j], dist[i - 1][j] + 1);
      if (j > 0) dist[i][j] = min(dist[i][j], dist[i][j - 1] + 1);
    }
  }
  cout << dist[h - 1][w - 1] << '\n';
  return 0;
}
0