結果
問題 |
No.2064 Smallest Sequence on Grid
|
ユーザー |
![]() |
提出日時 | 2022-09-02 21:26:21 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 529 ms / 3,000 ms |
コード長 | 936 bytes |
コンパイル時間 | 758 ms |
コンパイル使用メモリ | 74,440 KB |
実行使用メモリ | 50,304 KB |
最終ジャッジ日時 | 2024-11-16 02:15:49 |
合計ジャッジ時間 | 8,559 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#include <string> #include <vector> #include <iostream> using namespace std; int main() { int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) { cin >> S[i]; } vector<vector<int> > f(H, vector<int>(W, 0)); f[0][0] = 1; string answer(1, S[0][0]); for (int i = 0; i < H + W - 2; i++) { char minch = '~'; for (int x = 0; x < H; x++) { int y = i - x; if (!(0 <= y && y < W)) { continue; } if (f[x][y] == 1) { if (x != H - 1) { minch = min(minch, S[x + 1][y]); } if (y != W - 1) { minch = min(minch, S[x][y + 1]); } } } for (int x = 0; x < H; x++) { int y = i - x; if (!(0 <= y && y < W)) { continue; } if (f[x][y] == 1) { if (x != H - 1 && S[x + 1][y] == minch) { f[x + 1][y] = 1; } if (y != W - 1 && S[x][y + 1] == minch) { f[x][y + 1] = 1; } } } answer += minch; } cout << answer << endl; return 0; }