結果

問題 No.971 いたずらっ子
ユーザー MayimgMayimg
提出日時 2020-01-20 13:54:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 773 bytes
コンパイル時間 2,227 ms
コンパイル使用メモリ 200,364 KB
実行使用メモリ 23,296 KB
最終ジャッジ日時 2024-04-25 02:09:48
合計ジャッジ時間 3,729 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
23,168 KB
testcase_01 AC 50 ms
23,296 KB
testcase_02 AC 38 ms
18,176 KB
testcase_03 AC 37 ms
23,296 KB
testcase_04 AC 35 ms
22,144 KB
testcase_05 AC 33 ms
23,040 KB
testcase_06 AC 26 ms
18,688 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 11 ms
8,576 KB
testcase_09 AC 11 ms
8,320 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 2 ms
5,376 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