結果

問題 No.2064 Smallest Sequence on Grid
ユーザー TatsuyaaaaTatsuyaaaa
提出日時 2022-09-02 21:40:45
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 462 ms / 3,000 ms
コード長 1,333 bytes
コンパイル時間 2,376 ms
コンパイル使用メモリ 210,888 KB
実行使用メモリ 13,304 KB
最終ジャッジ日時 2023-08-10 03:36:40
合計ジャッジ時間 7,673 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 19 ms
12,872 KB
testcase_18 AC 18 ms
12,808 KB
testcase_19 AC 18 ms
12,792 KB
testcase_20 AC 334 ms
13,184 KB
testcase_21 AC 365 ms
13,204 KB
testcase_22 AC 242 ms
13,280 KB
testcase_23 AC 248 ms
13,272 KB
testcase_24 AC 245 ms
13,200 KB
testcase_25 AC 247 ms
13,284 KB
testcase_26 AC 457 ms
13,304 KB
testcase_27 AC 462 ms
13,204 KB
testcase_28 AC 18 ms
12,748 KB
testcase_29 AC 375 ms
11,500 KB
testcase_30 AC 16 ms
12,128 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