結果
問題 | No.2064 Smallest Sequence on Grid |
ユーザー |
![]() |
提出日時 | 2022-09-02 21:32:43 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 261 ms / 3,000 ms |
コード長 | 801 bytes |
コンパイル時間 | 2,035 ms |
コンパイル使用メモリ | 175,092 KB |
実行使用メモリ | 15,104 KB |
最終ジャッジ日時 | 2024-11-16 02:28:19 |
合計ジャッジ時間 | 6,640 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 29 |
ソースコード
#include <bits/stdc++.h>int ri() {int n;scanf("%d", &n);return n;}int main() {int h = ri();int w = ri();std::string s[h];for (auto &i : s) std::cin >> i;std::string res{s[0][0]};std::vector<int> cur = {0};for (int i = 1; i < h + w - 1; i++) {std::vector<int> xs;for (auto j : cur) {if (!xs.size() || xs.back() < j) xs.push_back(j);if (j + 1 < h && (!xs.size() || xs.back() < j + 1)) xs.push_back(j + 1);}char min = 'z' + 1;std::vector<int> mindex;for (auto x : xs) {if (i - x < 0 || i - x >= w) continue;if (min > s[x][i - x]) {min = s[x][i - x];mindex = {x};} else if (min == s[x][i - x]) mindex.push_back(x);}assert(mindex.size());cur = mindex;res.push_back(min);}std::cout << res << std::endl;return 0;}