結果

問題 No.2064 Smallest Sequence on Grid
ユーザー t98slidert98slider
提出日時 2022-09-02 21:33:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 818 ms / 3,000 ms
コード長 931 bytes
コンパイル時間 2,302 ms
コンパイル使用メモリ 186,024 KB
実行使用メモリ 16,256 KB
最終ジャッジ日時 2024-04-27 21:01:10
合計ジャッジ時間 10,576 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,944 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,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 220 ms
16,128 KB
testcase_18 AC 220 ms
16,128 KB
testcase_19 AC 218 ms
16,128 KB
testcase_20 AC 662 ms
16,128 KB
testcase_21 AC 655 ms
16,256 KB
testcase_22 AC 479 ms
16,256 KB
testcase_23 AC 508 ms
16,256 KB
testcase_24 AC 499 ms
16,256 KB
testcase_25 AC 499 ms
16,256 KB
testcase_26 AC 816 ms
16,256 KB
testcase_27 AC 818 ms
16,256 KB
testcase_28 AC 199 ms
16,128 KB
testcase_29 AC 666 ms
16,128 KB
testcase_30 AC 181 ms
15,360 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