結果

問題 No.2064 Smallest Sequence on Grid
ユーザー shoshoshomshoshoshom
提出日時 2022-09-02 23:07:26
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 656 bytes
コンパイル時間 2,139 ms
コンパイル使用メモリ 206,272 KB
実行使用メモリ 37,876 KB
最終ジャッジ日時 2024-04-27 22:47:41
合計ジャッジ時間 7,802 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

inline void min_self(string &a, string &b) {
  if (b < a) {
    a = b;
  }
}

int main() {
  iostream::sync_with_stdio(0), cin.tie(0), cout.tie(0);

  int h, w;
  cin >> h >> w;
  vector<string> grid(h);
  for (int i = 0; i < h; i++) {
    cin >> grid[i];
  }

  vector<string> dp(w, "{");
  dp[0] = "";

  for (int i = 0; i < h; i++) {
    vector<string> ndp(w, "{");
    for (int j = 0; j < w; j++) {
      string nst = dp[j] + grid[i][j];
      min_self(ndp[j], nst);
      if (j + 1 < w) {
        min_self(dp[j + 1], nst);
      }
    }
    swap(dp, ndp);
  }
  cout << dp[w - 1] << '\n';

  return 0;
}
0