結果

問題 No.2064 Smallest Sequence on Grid
ユーザー TatsuyaaaaTatsuyaaaa
提出日時 2022-09-02 21:40:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 467 ms / 3,000 ms
コード長 1,333 bytes
コンパイル時間 2,394 ms
コンパイル使用メモリ 214,900 KB
実行使用メモリ 13,312 KB
最終ジャッジ日時 2024-04-27 21:09:24
合計ジャッジ時間 7,383 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 19 ms
13,056 KB
testcase_18 AC 19 ms
13,056 KB
testcase_19 AC 20 ms
13,056 KB
testcase_20 AC 333 ms
13,184 KB
testcase_21 AC 365 ms
13,184 KB
testcase_22 AC 243 ms
13,184 KB
testcase_23 AC 246 ms
13,312 KB
testcase_24 AC 246 ms
13,184 KB
testcase_25 AC 246 ms
13,312 KB
testcase_26 AC 467 ms
13,312 KB
testcase_27 AC 465 ms
13,184 KB
testcase_28 AC 19 ms
12,928 KB
testcase_29 AC 376 ms
11,520 KB
testcase_30 AC 17 ms
12,160 KB
権限があれば一括ダウンロードができます

ソースコード

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;
        sort(vec.begin(), vec.end());
        vec.erase(unique(vec.begin(), vec.end()), vec.end());
        if (vec.size() == 0) break;
    }
    cout << ans << "\n";
    return 0;
}
0