結果

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int di[] = {1, 0};
int dj[] = {0, 1};

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 dp(h, vector<string>(w, "{"));
  dp[0][0] = "";

  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      string nst = dp[i][j] + grid[i][j];
      for (int k = 0; k < 2; k++) {
        int ni = i + di[k], nj = j + dj[k];
        if (ni < h && nj < w) {
          min_self(dp[ni][nj], nst);
        }
      }
    }
  }
  string ans = dp[h - 1][w - 1];
  ans += grid[h - 1][w - 1];
  cout << ans << '\n';


  return 0;
}
0