結果

問題 No.2064 Smallest Sequence on Grid
ユーザー rogi52rogi52
提出日時 2022-10-08 16:36:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 3,000 ms
コード長 1,178 bytes
コンパイル時間 2,536 ms
コンパイル使用メモリ 211,640 KB
実行使用メモリ 13,268 KB
最終ジャッジ日時 2023-09-04 22:06:42
合計ジャッジ時間 7,011 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 1 ms
4,380 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 17 ms
12,840 KB
testcase_18 AC 18 ms
12,820 KB
testcase_19 AC 18 ms
12,896 KB
testcase_20 AC 258 ms
13,252 KB
testcase_21 AC 281 ms
13,268 KB
testcase_22 AC 189 ms
13,128 KB
testcase_23 AC 187 ms
13,200 KB
testcase_24 AC 186 ms
13,248 KB
testcase_25 AC 188 ms
13,180 KB
testcase_26 AC 357 ms
13,208 KB
testcase_27 AC 356 ms
13,192 KB
testcase_28 AC 18 ms
12,832 KB
testcase_29 AC 296 ms
11,600 KB
testcase_30 AC 17 ms
12,200 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

    string T = "";
    T += S[0][0];
    vector<pair<int,int>> can = {{0, 0}};
    while(int(T.size()) < H + W - 1) {
        char mi = 'z';
        vector<pair<int,int>> nt;
        for(auto [x, y] : can) {
            if(x + 1 < H) {
                if(S[x + 1][y] < mi) {
                    mi = S[x + 1][y];
                    nt = {{x + 1, y}};
                } else if(S[x + 1][y] == mi) {
                    nt.push_back({x + 1, y});
                }
            }
            if(y + 1 < W) {
                if(S[x][y + 1] < mi) {
                    mi = S[x][y + 1];
                    nt = {{x, y + 1}};
                } else if(S[x][y + 1] == mi) {
                    nt.push_back({x, y + 1});
                }
            }
        }
        sort(nt.begin(), nt.end());
        nt.erase(unique(nt.begin(), nt.end()), nt.end());
        swap(can, nt);
        T += mi;
    }

    cout << T << endl;
}
0