結果

問題 No.2064 Smallest Sequence on Grid
ユーザー yansi819yansi819
提出日時 2024-04-13 19:09:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 347 ms / 3,000 ms
コード長 1,024 bytes
コンパイル時間 5,126 ms
コンパイル使用メモリ 260,444 KB
実行使用メモリ 16,384 KB
最終ジャッジ日時 2024-04-13 19:09:55
合計ジャッジ時間 11,069 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 172 ms
16,256 KB
testcase_18 AC 172 ms
16,128 KB
testcase_19 AC 172 ms
16,256 KB
testcase_20 AC 293 ms
16,128 KB
testcase_21 AC 303 ms
16,384 KB
testcase_22 AC 250 ms
16,256 KB
testcase_23 AC 259 ms
16,256 KB
testcase_24 AC 260 ms
16,256 KB
testcase_25 AC 256 ms
16,128 KB
testcase_26 AC 347 ms
16,384 KB
testcase_27 AC 339 ms
16,256 KB
testcase_28 AC 174 ms
16,128 KB
testcase_29 AC 282 ms
16,256 KB
testcase_30 AC 158 ms
15,488 KB
権限があれば一括ダウンロードができます

ソースコード

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];
  int dx[2] = {1, 0};
  int dy[2] = {0, 1};
  vector<vector<bool>> vis(H, vector<bool>(W, false));
  vector<pair<int, int>> A, B;
  A.emplace_back(0, 0);
  vis[0][0] = true;
  string ans;
  ans += S[0][0];
  for (int i = 0; i < H + W - 2; i++) {
    B.clear();
    char c = char('z' + 1);
    for (auto &p: A) {
      for (int j = 0; j < 2; j++) {
        int nx = p.first + dx[j];
        int ny = p.second + dy[j];
        if (nx >= H || ny >= W) continue;
        if (vis[nx][ny]) continue;
        if (c >= S[nx][ny]) {
          if (c > S[nx][ny]) B.clear();
          c = S[nx][ny];
          B.emplace_back(nx, ny);
          vis[nx][ny] = true;
        }
      }
    }
    ans += c;
    swap(A, B);
  }
  cout << ans << endl;
  return 0;
}
0