結果

問題 No.971 いたずらっ子
ユーザー 0w10w1
提出日時 2020-01-20 00:24:11
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 892 bytes
コンパイル時間 2,547 ms
コンパイル使用メモリ 213,676 KB
実行使用メモリ 23,948 KB
最終ジャッジ日時 2023-09-15 20:34:19
合計ジャッジ時間 10,872 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 590 ms
23,468 KB
testcase_04 AC 550 ms
22,068 KB
testcase_05 AC 591 ms
23,540 KB
testcase_06 AC 444 ms
19,024 KB
testcase_07 WA -
testcase_08 AC 137 ms
8,760 KB
testcase_09 AC 134 ms
8,508 KB
testcase_10 AC 4 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 WA -
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main() {
  ios::sync_with_stdio(false);

  int H, W;
  cin >> H >> W;

  vector<string> G(H);
  for (int i = 0; i < H; ++i) {
    cin >> G[i];
  }

  const int INF = 0x3f3f3f3f;
  vector<vector<int>> dp(H, vector<int>(W, INF));

  set<tuple<int, int, int>> pq;
  pq.emplace(dp[0][0] = 0, 0, 0);
  while (pq.size()) {
    int d;
    int x, y;
    tie(d, x, y) = *pq.begin();
    pq.erase(pq.begin());
    if (d != dp[x][y]) continue;
    static int dx[] = { 1, 0, -1, 0 };
    static int dy[] = { 0, 1, 0, -1 };
    for (int di = 0; di < 4; ++di) {
      int nx = x + dx[di];
      int ny = y + dy[di];
      if (nx < 0 || nx == H || ny < 0 || ny == W) continue;
      int nd = d + (G[x][y] == 'k' ? x + y : 0) + 1;
      if (nd < dp[nx][ny]) pq.emplace(dp[nx][ny] = nd, nx, ny);
    }
  }

  cout << dp[H - 1][W - 1] << endl;

  return 0;
}
0