結果

問題 No.2064 Smallest Sequence on Grid
ユーザー TatsuyaaaaTatsuyaaaa
提出日時 2022-09-02 21:38:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,233 bytes
コンパイル時間 1,875 ms
コンパイル使用メモリ 210,564 KB
実行使用メモリ 814,324 KB
最終ジャッジ日時 2024-04-27 21:06:34
合計ジャッジ時間 5,680 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<int> dx = {1, 0};
vector<int> dy = {0, 1};

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    vector<string> S(H);
    for (int i=0;i<H;i++) cin >> S[i];

    string ans = "";
    vector<pair<int, int>> vec;
    vec.push_back(make_pair(0, 0));
    while (true) {
        ans += S[vec[0].first][vec[0].second];
        vector<pair<int, int>> vec_nxt;
        char c_max = '{';
        for (auto ele : vec) {
            for (int i=0;i<2;i++) {
                int i_nxt = ele.first + dx[i];
                int j_nxt = ele.second + dy[i];
                if (!(0 <= i_nxt && i_nxt < H)) continue;
                if (!(0 <= j_nxt && j_nxt < W)) continue;
                if (S[i_nxt][j_nxt] < c_max) {
                    vec_nxt.clear();
                    c_max = S[i_nxt][j_nxt];
                    vec_nxt.push_back(make_pair(i_nxt, j_nxt));
                } else if (S[i_nxt][j_nxt] == c_max) {
                    vec_nxt.push_back(make_pair(i_nxt, j_nxt));
                }
            }
        }
        vec = vec_nxt;
        if (vec.size() == 0) break;
    }
    cout << ans << "\n";
    return 0;
}
0