結果
問題 |
No.2064 Smallest Sequence on Grid
|
ユーザー |
|
提出日時 | 2022-12-13 19:52:57 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 336 ms / 3,000 ms |
コード長 | 1,030 bytes |
コンパイル時間 | 664 ms |
コンパイル使用メモリ | 75,492 KB |
最終ジャッジ日時 | 2025-02-09 11:04:27 |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#include <iostream> #include <vector> using namespace std; typedef pair<int, int> P; int main() { int h, w; cin >> h >> w; string s[3005]; for(int i = 0; i < h; i++) { cin >> s[i]; } cout << s[0][0]; vector<P> v; v.push_back(P(0, 0)); for(int i = 1; i < h + w - 1; i++) { char l = 'z'; for(auto [x, y] : v) { if(x < h - 1) { l = min(l, s[x + 1][y]); } if(y < w - 1) { l = min(l, s[x][y + 1]); } } cout << l; vector<P> z; for(auto [x, y] : v) { if(x < h - 1 && s[x + 1][y] == l && (z.empty() || z.back().second != y)) { z.push_back(P(x + 1, y)); } if(y < w - 1 && s[x][y + 1] == l && (z.empty() || z.back().first != x)) { z.push_back(P(x, y + 1)); } } swap(v, z); } cout << endl; }