結果

問題 No.2064 Smallest Sequence on Grid
ユーザー wanuiwanui
提出日時 2022-09-02 22:12:54
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,294 bytes
コンパイル時間 2,125 ms
コンパイル使用メモリ 208,436 KB
実行使用メモリ 727,000 KB
最終ジャッジ日時 2024-04-27 21:47:21
合計ジャッジ時間 7,819 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,760 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 3 ms
6,940 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 MLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
// clang-format off
using namespace std; using ll=long long; using ull=unsigned long long; using pll=pair<ll,ll>; const ll INF=4e18;
void print0(){}; template<typename H,typename... T> void print0(H h,T... t){cout<<h;print0(t...);}
void print(){print0("\n");}; template<typename H,typename... T>void print(H h,T... t){print0(h);if(sizeof...(T)>0)print0(" ");print(t...);}
void perr0(){}; template<typename H,typename... T> void perr0(H h,T... t){cerr<<h;perr0(t...);}
void perr(){perr0("\n");}; template<typename H,typename... T>void perr(H h,T... t){perr0(h);if(sizeof...(T)>0)perr0(" ");perr(t...);}
void ioinit() { cout<<fixed<<setprecision(15); cerr<<fixed<<setprecision(6); ios_base::sync_with_stdio(0); cin.tie(0); }
#define rep(i,n) for(int i=0;i<(n);i++)
// clang-format on

using pii = pair<int, int>;
char S[3002][3002];
bool iscand[3002][3002];
int h, w;
bool valid(pii x) {
    if (x.first >= h || x.second >= w || x.first < 0 || x.second < 0) return false;
    return true;
}
int main() {
    ioinit();

    cin >> h >> w;

    rep(i, h) {
        rep(j, w) {
            char c;
            cin >> c;
            S[i][j] = c;
        }
    }
    char terminal = S[h - 1][w - 1];

    string ans = {S[0][0]};
    vector<pii> cands = {{0, 0}};
    while (true) {
        vector<pii> ncands;
        char minchar = 'z' + 1;
        for (auto cand : cands) {
            pii na = {cand.first + 1, cand.second};
            pii nb = {cand.first, cand.second + 1};
            if (valid(na)) {
                if (minchar > S[na.first][na.second]) {
                    minchar = S[na.first][na.second];
                    ncands = {na};
                } else if (minchar == S[na.first][na.second]) {
                    ncands.push_back(na);
                }
            }
            if (valid(nb)) {
                if (minchar > S[nb.first][nb.second]) {
                    minchar = S[nb.first][nb.second];
                    ncands = {nb};
                } else if (minchar == S[nb.first][nb.second]) {
                    ncands.push_back(nb);
                }
            }
        }
        if (ncands.size() == 0) {
            break;
        }
        ans.push_back(minchar);
        swap(cands, ncands);
    }
    print(ans);
    return 0;
}
0