結果
| 問題 | 
                            No.2064 Smallest Sequence on Grid
                             | 
                    
| コンテスト | |
| ユーザー | 
                             srjywrdnprkt
                         | 
                    
| 提出日時 | 2023-05-05 19:41:27 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,545 ms / 3,000 ms | 
| コード長 | 1,253 bytes | 
| コンパイル時間 | 1,462 ms | 
| コンパイル使用メモリ | 125,516 KB | 
| 最終ジャッジ日時 | 2025-02-12 17:20:25 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 29 | 
ソースコード
#include <iostream>
#include <vector>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <numeric>
#include <deque>
#include <complex>
#include <cassert>
using namespace std;
int main(){
    int H, W, h, w, nh, nw;
    char mc;
    string ans="";
    cin >> H >> W;
    vector<string> S(H);
    
    int dx[2] = {1, 0};
    int dy[2] = {0, 1};
    vector<pair<int, int>> v;
    for (int i=0; i < H; i++) cin >> S[i];
    ans += S[0][0];
    v.push_back({0, 0});
    for (int i=1; i<H+W-1; i++){
        vector<tuple<char, int, int>> c;
        set<pair<int, int>> st;
        for (auto [h, w] : v){
            for (int dir=0; dir < 2; dir++){
                nh = h + dx[dir];
                nw = w + dy[dir];
                if (nh < 0 || nh >= H || nw < 0 || nw >= W) continue;
                if (st.count({nh, nw})) continue;
                c.push_back({S[nh][nw], nh, nw});
                st.insert({nh, nw});
            }
        }
        v.clear();
        sort(c.begin(), c.end());
        tie(mc, h, w) = c[0];
        ans += mc;
        for (auto [cc, h, w] : c){
            if (cc == mc) v.push_back({h, w});
        }
    }
    cout << ans << endl;
    return 0;
}
            
            
            
        
            
srjywrdnprkt