結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             やう
                         | 
                    
| 提出日時 | 2022-09-02 21:50:24 | 
| 言語 | C++14  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                TLE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 958 bytes | 
| コンパイル時間 | 2,272 ms | 
| コンパイル使用メモリ | 186,180 KB | 
| 実行使用メモリ | 74,480 KB | 
| 最終ジャッジ日時 | 2024-11-16 03:10:00 | 
| 合計ジャッジ時間 | 32,133 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge4 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 25 TLE * 4 | 
ソースコード
#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));
        for(auto i=s.begin();i!=s.end();++i){
            P p=*i;
            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});
        }
        if(b.size()==0) break;
        while(s.size()) s.erase(s.begin());
        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;
}
            
            
            
        
            
やう