結果

問題 No.2064 Smallest Sequence on Grid
ユーザー t98slidert98slider
提出日時 2022-09-02 21:33:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 867 ms / 3,000 ms
コード長 931 bytes
コンパイル時間 1,962 ms
コンパイル使用メモリ 184,292 KB
実行使用メモリ 16,380 KB
最終ジャッジ日時 2023-08-10 03:28:15
合計ジャッジ時間 10,791 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 196 ms
16,072 KB
testcase_18 AC 197 ms
16,012 KB
testcase_19 AC 195 ms
15,976 KB
testcase_20 AC 645 ms
16,096 KB
testcase_21 AC 694 ms
16,124 KB
testcase_22 AC 500 ms
16,188 KB
testcase_23 AC 529 ms
16,088 KB
testcase_24 AC 529 ms
16,380 KB
testcase_25 AC 528 ms
16,220 KB
testcase_26 AC 867 ms
16,316 KB
testcase_27 AC 866 ms
16,120 KB
testcase_28 AC 196 ms
16,028 KB
testcase_29 AC 707 ms
15,960 KB
testcase_30 AC 178 ms
15,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> A(h);
    for(auto &&s:A)cin >> s;
    vector<vector<bool>> dp(h, vector<bool>(w));
    dp[0][0] = true;
    string ans;
    ans += A[0][0];
    for(int len = 0; len < h + w - 2; len++){
        vector<tuple<char,int,int>> q;
        for(int y = 0; y <= len; y++){
            int x = len - y;
            if(x < 0 || y >= h || y < 0 || x >= w)continue;
            if(!dp[y][x])continue;
            if(y + 1 < h)q.emplace_back(A[y + 1][x], y + 1, x);
            if(x + 1 < w)q.emplace_back(A[y][x + 1], y, x + 1);
        }
        sort(q.begin(), q.end());
        char c, o = get<0>(q[0]);
        int y, x;
        ans += o;
        for(int i = 0; i < q.size() && get<0>(q[i]) == o; i++){
            tie(c, y, x) = q[i];
            dp[y][x] = true;
        }
    }
    cout << ans << '\n';
}
0