結果

問題 No.2064 Smallest Sequence on Grid
ユーザー やうやう
提出日時 2022-09-02 21:54:24
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 933 bytes
コンパイル時間 1,966 ms
コンパイル使用メモリ 187,004 KB
実行使用メモリ 141,912 KB
最終ジャッジ日時 2024-11-16 03:16:37
合計ジャッジ時間 34,165 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 24 TLE * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
using V=vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll i=1;i<=n;i++)

int main(){
    int h,w;
    cin >> h >> w;
    vector<V> a(h,V(w));
    rep(i,h) rep(j,w){
        char c;
        cin >> c;
        a[i][j]=c-'a';
    }

    string t; t+=(char)('a'+a[0][0]);
    set<P> s; s.insert(P(0,0));
    while(t.size()<h+w+1){
        vector<V> b(0,V(3));
        while(s.size()){
            P p=*s.begin();
            int x=p.first,y=p.second;
            if(x+1<h) b.push_back(V{a[x+1][y],x+1,y});
            if(y+1<w) b.push_back(V{a[x][y+1],x,y+1});
            s.erase(s.begin());
        }
        if(b.size()==0) break;
        sort(b.begin(),b.end());
        t+=(char)('a'+b[0][0]);
        rep(i,b.size()) if(b[i][0]==b[0][0]) s.insert(P(b[i][1],b[i][2]));
    }

    cout << t << endl;

}
0