結果

問題 No.2064 Smallest Sequence on Grid
ユーザー a16784542a16784542
提出日時 2022-09-25 21:57:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,372 ms / 3,000 ms
コード長 2,482 bytes
コンパイル時間 4,305 ms
コンパイル使用メモリ 270,924 KB
実行使用メモリ 16,548 KB
最終ジャッジ日時 2023-08-24 02:12:24
合計ジャッジ時間 16,769 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,504 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 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,376 KB
testcase_17 AC 161 ms
16,116 KB
testcase_18 AC 161 ms
16,084 KB
testcase_19 AC 159 ms
16,052 KB
testcase_20 AC 980 ms
16,240 KB
testcase_21 AC 1,059 ms
16,268 KB
testcase_22 AC 738 ms
16,240 KB
testcase_23 AC 760 ms
16,264 KB
testcase_24 AC 765 ms
16,332 KB
testcase_25 AC 765 ms
16,548 KB
testcase_26 AC 1,372 ms
16,500 KB
testcase_27 AC 1,361 ms
16,500 KB
testcase_28 AC 163 ms
16,176 KB
testcase_29 AC 1,127 ms
16,260 KB
testcase_30 AC 146 ms
15,244 KB
権限があれば一括ダウンロードができます

ソースコード

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;

struct abc{
    char a;
    int b,c;
    abc(char a='a',ll b=0,ll c=0):a(a),b(b),c(c){}
    
    // comp(a,b)==comp(b,a)==true を満たすような例が存在するとRE
    bool operator<(const abc &x) const{
        return a<x.a;
    }
};

// bool operator<(const abc& lhs, const abc& rhs)
// {
//   return lhs.a < rhs.a;
// }


signed main() {
    int h,w;cin>>h>>w;
    V<string> s(h);
    rep(i,h)cin>>s[i];
    
    const int d[]={0,1,0};
    string ans;
    deque<abc> dq;
    dq.emplace_back(s[0][0],0,0);
    V<V<bool>> col(h,V<bool>(w));
    while(sz(dq)){
        multiset<abc> st;
        ans += dq.front().a;
        int n=sz(dq);
        rep(i,n){
            auto [a,b,c]=dq.front();
            dq.pop_front();
            rep(j,2){
                int nb=b+d[j];
                int nc=c+d[j+1];
                if(nb>=h||nc>=w||col[nb][nc])continue;
                st.emplace(s[nb][nc],nb,nc);
                col[nb][nc]=1;
            }
        }
        if(sz(st)==0)break;
        char t=st.begin()->a;
        for(auto [a,b,c]:st){
            if(t==a)dq.emplace_back(a,b,c);
            else break;
        }
    }
    cout<<ans<<endl;
    return 0;
}
0