結果

問題 No.2064 Smallest Sequence on Grid
ユーザー a16784542a16784542
提出日時 2022-09-25 20:39:22
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,843 bytes
コンパイル時間 4,857 ms
コンパイル使用メモリ 280,208 KB
実行使用メモリ 814,804 KB
最終ジャッジ日時 2023-08-24 01:51:25
合計ジャッジ時間 8,727 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 WA -
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
4,380 KB
testcase_13 WA -
testcase_14 MLE -
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>
#include <atcoder/all>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace atcoder;
// using namespace __gnu_pbds;

using ll=long long;
#define int ll
using ld = long double;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for(int i=int(n-1);i>=int(0);--i)
#define fore(i,a) for(auto &i:a)
#define all(x) x.begin(),x.end() 
#define sz(x) ((int)(x).size())
#define bp(x) (__builtin_popcount((long long)(x)))
#define pb push_back
#define eb emplace_back
#define mpa make_pair
#define bit(n) (1LL<<(n))
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using max_heap = priority_queue<T>;
template <class T> using min_heap = priority_queue<T, vector<T>, greater<>>;
#define P pair<int,int>
#define TP tuple<int,int,int>
#define F first
#define S second
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1001001001;
const ll INFL = 3e18;
const int MAX = 2e6+1;

signed main() {
    int h,w;cin>>h>>w;
    V<string> s(h);
    rep(i,h)cin>>s[i];
    // if(h==1&&w==1){
    //     cout<<s[0][0]<<endl;
    //     return 0;
    // }
    V<P> ans;
    ans.emplace_back(0,0);
    deque<P> dq;
    int nowh=0,noww=0;
    const int d[]={0,1,0};
    V<V<int>> col(h,V<int>(w));
    while(!(nowh==h-1&&noww==w-1)){
        deque<TP> dq;
        dq.emplace_back(nowh,noww,0);
        int p=0;
        set<char> st;
        int nexth=-1,nextw=-1;
        while(sz(dq)){
            auto [a,b,c]=dq.front();
            dq.pop_front();
            if(p!=c){
                if(sz(st)!=1||(a==h-1&&b==w-1)){
                    ans.emplace_back(nexth,nextw);
                    nowh=nexth;
                    noww=nextw;
                    break;
                }
                st.clear();
            }
            p=c;
            rep(i,2){
                int na=a+d[i];
                int nb=b+d[i+1];
                if(na>=h||nb>=w||col[na][nb])continue;
                dq.emplace_back(na,nb,c+1);
                st.insert(s[na][nb]);
                // col[na][nb]=1;
                if(s[na][nb]<=*st.begin()){
                    nexth=na;
                    nextw=nb;
                }
            }
        }
    }
    string x;
    rep(i,1,sz(ans)){
        rep(j,ans[i-1].first,ans[i].first){
            x+=s[j][ans[i-1].second];
        }
        rep(j,ans[i-1].second,ans[i].second){
            x+=s[ans[i].first][j];
        }
    }
    x+=s[h-1][w-1];
    cout<<x<<endl;
    return 0;
}
0