結果

問題 No.2064 Smallest Sequence on Grid
ユーザー shoshoshom
提出日時 2022-09-02 23:07:26
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 656 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 198,328 KB
最終ジャッジ日時 2025-02-07 01:48:15
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 TLE * 14
権限があれば一括ダウンロードができます

ソースコード

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