結果

問題 No.2064 Smallest Sequence on Grid
ユーザー erbowlerbowl
提出日時 2022-09-04 16:22:43
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
AC  
実行時間 2,085 ms / 3,000 ms
コード長 932 bytes
コンパイル時間 2,265 ms
コンパイル使用メモリ 213,496 KB
実行使用メモリ 436,808 KB
最終ジャッジ日時 2024-11-18 22:13:57
合計ジャッジ時間 19,106 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #

typedef int ll;
typedef long double ld;
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main(){
    ll h,w;
    std::cin >> h>>w;
    vector<string> s(h);
    for (int i = 0; i < h; i++) {
        std::cin >> s[i];
    }
    vector<set<pair<ll,ll>>> kou(h+w+3);
    kou[0].insert({0,0});
    string ans = "";
    for (int i = 0; i < h+w-1; i++) {
        ll minc = 1000;
        for (auto e : kou[i]) {
            minc = min(minc, (ll)s[e.first][e.second]);
        }
        // std::cout << minc << std::endl;
        ans.push_back(minc);
        for (auto e : kou[i]) {
            if(s[e.first][e.second]==minc){
                if(e.first+1<h){
                    kou[i+1].insert({e.first+1,e.second});
                }
                if(e.second+1<w){
                    kou[i+1].insert({e.first,e.second+1});
                }
            }
        }
    }
    std::cout << ans << std::endl;
}
0