結果

問題 No.2064 Smallest Sequence on Grid
ユーザー kyo1kyo1
提出日時 2022-09-02 21:44:26
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 776 bytes
コンパイル時間 2,215 ms
コンパイル使用メモリ 205,716 KB
実行使用メモリ 724,276 KB
最終ジャッジ日時 2023-08-10 03:41:25
合計ジャッジ時間 7,980 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
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>

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (auto &&e : S) {
    cin >> e;
  }
  string res = "";
  res += S[0][0];
  vector<pair<int, int>> X;
  X.emplace_back(0, 0);
  for (int i = 0; i < H + W - 2; i++) {
    char c = 'z';
    for (const auto &[y, x] : X) {
      if (y + 1 < H && c > S[y + 1][x]) c = S[y + 1][x];
      if (x + 1 < W && c > S[y][x + 1]) c = S[y][x + 1];
    }
    vector<pair<int, int>> Y;
    for (const auto &[y, x] : X) {
      if (y + 1 < H && c == S[y + 1][x]) Y.emplace_back(y + 1, x);
      if (x + 1 < W && c == S[y][x + 1]) Y.emplace_back(y, x + 1);
    }
    res += c;
    swap(X, Y);
  }
  cout << res << '\n';
  return 0;
}
0