結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー | yansi819 |
提出日時 | 2024-04-13 19:09:43 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 360 ms / 3,000 ms |
コード長 | 1,024 bytes |
コンパイル時間 | 4,429 ms |
コンパイル使用メモリ | 268,648 KB |
実行使用メモリ | 16,256 KB |
最終ジャッジ日時 | 2024-10-03 00:20:25 |
合計ジャッジ時間 | 10,129 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h> #include <atcoder/all> using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; int main() { int H, W; cin >> H >> W; vector<string> S(H); for (int i = 0; i < H; i++) cin >> S[i]; int dx[2] = {1, 0}; int dy[2] = {0, 1}; vector<vector<bool>> vis(H, vector<bool>(W, false)); vector<pair<int, int>> A, B; A.emplace_back(0, 0); vis[0][0] = true; string ans; ans += S[0][0]; for (int i = 0; i < H + W - 2; i++) { B.clear(); char c = char('z' + 1); for (auto &p: A) { for (int j = 0; j < 2; j++) { int nx = p.first + dx[j]; int ny = p.second + dy[j]; if (nx >= H || ny >= W) continue; if (vis[nx][ny]) continue; if (c >= S[nx][ny]) { if (c > S[nx][ny]) B.clear(); c = S[nx][ny]; B.emplace_back(nx, ny); vis[nx][ny] = true; } } } ans += c; swap(A, B); } cout << ans << endl; return 0; }