結果

問題 No.2064 Smallest Sequence on Grid
ユーザー やうやう
提出日時 2022-09-02 22:18:20
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 2,320 ms / 3,000 ms
コード長 1,005 bytes
コンパイル時間 2,025 ms
コンパイル使用メモリ 176,624 KB
実行使用メモリ 460,556 KB
最終ジャッジ日時 2023-08-10 04:33:12
合計ジャッジ時間 21,942 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 3 ms
4,384 KB
testcase_17 AC 401 ms
38,920 KB
testcase_18 AC 407 ms
39,172 KB
testcase_19 AC 417 ms
38,916 KB
testcase_20 AC 1,809 ms
343,692 KB
testcase_21 AC 1,900 ms
370,260 KB
testcase_22 AC 1,377 ms
261,516 KB
testcase_23 AC 1,366 ms
249,756 KB
testcase_24 AC 1,384 ms
249,916 KB
testcase_25 AC 1,366 ms
249,924 KB
testcase_26 AC 2,320 ms
460,556 KB
testcase_27 AC 2,320 ms
460,476 KB
testcase_28 AC 415 ms
39,088 KB
testcase_29 AC 1,963 ms
387,780 KB
testcase_30 AC 379 ms
36,100 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<int,int>;
using V=vector<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int 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]);
    vector<set<P>> s(h+w-1);
    s[0].insert(P(0,0));
    rep(l,h+w-2){
        int c=100;
        for(auto i=s[l].begin();i!=s[l].end();++i){
            P p=*i;
            int x=p.first,y=p.second;
            if(x+1<h) c=min(c,a[x+1][y]);
            if(y+1<w) c=min(c,a[x][y+1]);
        }
        for(auto i=s[l].begin();i!=s[l].end();++i){
            P p=*i;
            int x=p.first,y=p.second;
            if(x+1<h) if(a[x+1][y]==c) s[l+1].insert(P(x+1,y));
            if(y+1<w) if(a[x][y+1]==c) s[l+1].insert(P(x,y+1));
        }
        t+=(char)('a'+c);
    }

    cout << t << endl;

}
0