結果

問題 No.2064 Smallest Sequence on Grid
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-05-05 19:41:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,633 ms / 3,000 ms
コード長 1,253 bytes
コンパイル時間 1,478 ms
コンパイル使用メモリ 130,348 KB
実行使用メモリ 15,100 KB
最終ジャッジ日時 2023-08-15 01:25:00
合計ジャッジ時間 15,286 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 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,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 163 ms
14,820 KB
testcase_18 AC 163 ms
14,768 KB
testcase_19 AC 163 ms
14,960 KB
testcase_20 AC 1,207 ms
14,888 KB
testcase_21 AC 1,292 ms
14,904 KB
testcase_22 AC 907 ms
15,100 KB
testcase_23 AC 904 ms
14,956 KB
testcase_24 AC 891 ms
15,076 KB
testcase_25 AC 892 ms
15,004 KB
testcase_26 AC 1,633 ms
14,844 KB
testcase_27 AC 1,627 ms
15,084 KB
testcase_28 AC 163 ms
14,972 KB
testcase_29 AC 1,342 ms
14,988 KB
testcase_30 AC 150 ms
14,260 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>

using namespace std;

int main(){

    int H, W, h, w, nh, nw;
    char mc;
    string ans="";
    cin >> H >> W;
    vector<string> S(H);
    
    int dx[2] = {1, 0};
    int dy[2] = {0, 1};
    vector<pair<int, int>> v;

    for (int i=0; i < H; i++) cin >> S[i];
    ans += S[0][0];
    v.push_back({0, 0});

    for (int i=1; i<H+W-1; i++){
        vector<tuple<char, int, int>> c;
        set<pair<int, int>> st;
        for (auto [h, w] : v){
            for (int dir=0; dir < 2; dir++){
                nh = h + dx[dir];
                nw = w + dy[dir];
                if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
                if (st.count({nh, nw})) continue;
                c.push_back({S[nh][nw], nh, nw});
                st.insert({nh, nw});
            }
        }
        v.clear();
        sort(c.begin(), c.end());
        tie(mc, h, w) = c[0];
        ans += mc;
        for (auto [cc, h, w] : c){
            if (cc == mc) v.push_back({h, w});
        }
    }

    cout << ans << endl;

    return 0;
}
0