結果
問題 |
No.2064 Smallest Sequence on Grid
|
ユーザー |
|
提出日時 | 2022-09-02 21:33:51 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 868 ms / 3,000 ms |
コード長 | 931 bytes |
コンパイル時間 | 2,059 ms |
コンパイル使用メモリ | 187,436 KB |
実行使用メモリ | 16,256 KB |
最終ジャッジ日時 | 2024-11-16 02:31:13 |
合計ジャッジ時間 | 10,934 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#include<bits/stdc++.h> using namespace std; using ll = long long; int main(){ int h, w; cin >> h >> w; vector<string> A(h); for(auto &&s:A)cin >> s; vector<vector<bool>> dp(h, vector<bool>(w)); dp[0][0] = true; string ans; ans += A[0][0]; for(int len = 0; len < h + w - 2; len++){ vector<tuple<char,int,int>> q; for(int y = 0; y <= len; y++){ int x = len - y; if(x < 0 || y >= h || y < 0 || x >= w)continue; if(!dp[y][x])continue; if(y + 1 < h)q.emplace_back(A[y + 1][x], y + 1, x); if(x + 1 < w)q.emplace_back(A[y][x + 1], y, x + 1); } sort(q.begin(), q.end()); char c, o = get<0>(q[0]); int y, x; ans += o; for(int i = 0; i < q.size() && get<0>(q[i]) == o; i++){ tie(c, y, x) = q[i]; dp[y][x] = true; } } cout << ans << '\n'; }