結果

問題 No.2064 Smallest Sequence on Grid
ユーザー shoshoshomshoshoshom
提出日時 2022-09-02 23:01:29
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 791 bytes
コンパイル時間 2,527 ms
コンパイル使用メモリ 207,416 KB
実行使用メモリ 813,568 KB
最終ジャッジ日時 2024-04-27 22:40:38
合計ジャッジ時間 4,770 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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