結果

問題 No.2064 Smallest Sequence on Grid
ユーザー hourenhouren
提出日時 2022-09-02 21:48:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 900 ms / 3,000 ms
コード長 1,180 bytes
コンパイル時間 1,937 ms
コンパイル使用メモリ 183,308 KB
実行使用メモリ 14,192 KB
最終ジャッジ日時 2023-08-10 03:44:54
合計ジャッジ時間 10,167 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 2 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 20 ms
14,120 KB
testcase_18 AC 20 ms
14,136 KB
testcase_19 AC 20 ms
14,172 KB
testcase_20 AC 659 ms
14,164 KB
testcase_21 AC 720 ms
14,148 KB
testcase_22 AC 477 ms
14,136 KB
testcase_23 AC 456 ms
14,100 KB
testcase_24 AC 454 ms
14,128 KB
testcase_25 AC 455 ms
14,164 KB
testcase_26 AC 900 ms
14,192 KB
testcase_27 AC 898 ms
14,140 KB
testcase_28 AC 19 ms
14,184 KB
testcase_29 AC 742 ms
12,328 KB
testcase_30 AC 18 ms
13,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using T = tuple<int,int,int>;
#define fix(x) fixed << setprecision(x)
#define asc(x) x, vector<x>, greater<x>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmin(T&a, const T&b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool chmax(T&a, const T&b){if(a<b){a=b;return 1;}return 0;}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int h,w;
    cin >> h >> w;
    vector<int> ans(h+w-1,1001001001);
    vector<string> s(h);
    rep(i,h) cin >> s[i];
    priority_queue<asc(T)> pq;
    pq.push({0,s[0][0],0});
    vector<vector<bool>> seen(h,vector<bool>(w,false));
    seen[0][0] = true;
    while(pq.size()){
        int p,x,q;
        tie(p,x,q) = pq.top();
        pq.pop();
        if(ans[p]<x) continue;
        ans[p] = x;
        p -= q;
        if(p!=h-1 && !seen[p+1][q]) {pq.push({p+q+1,s[p+1][q],q}); seen[p+1][q] = true;}
        if(q!=w-1 && !seen[p][q+1]) {pq.push({p+q+1,s[p][q+1],q+1}); seen[p][q+1] = true;}
    }
    rep(i,h+w-1) cout << (char)ans[i];
    cout << '\n';
    return 0;
}
0