結果

問題 No.2064 Smallest Sequence on Grid
ユーザー yansi819yansi819
提出日時 2024-04-13 17:44:48
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 909 bytes
コンパイル時間 5,242 ms
コンパイル使用メモリ 261,620 KB
実行使用メモリ 814,464 KB
最終ジャッジ日時 2024-04-13 17:44:59
合計ジャッジ時間 9,411 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 5 ms
6,940 KB
testcase_13 AC 7 ms
6,940 KB
testcase_14 AC 8 ms
6,940 KB
testcase_15 AC 5 ms
6,940 KB
testcase_16 AC 7 ms
6,944 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int main() {
  int H, W; cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) cin >> S[i];
  string ans = string(H + W - 1, 'z');
  vector<vector<string>> T(H, vector<string>(W, ans));
  queue<int> que;
  string s = string(1, S[0][0]);
  que.push(0);
  T[0][0] = s;
  int dx[2] = {1, 0};
  int dy[2] = {0, 1};
  while (!que.empty()) {
    auto &id = que.front(); que.pop();
    int x = id / W;
    int y = id % W;
    for (int i = 0; i < 2; i++) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (nx >= H || ny >= W) continue;
      if (T[nx][ny] > T[x][y] + S[nx][ny]) {
        T[nx][ny] = T[x][y] + S[nx][ny];
        que.push(nx * W + ny);
      }
    }
  }
  cout << T[H - 1][W - 1] << endl;
  return 0;
}
0