結果

問題 No.2064 Smallest Sequence on Grid
ユーザー やうやう
提出日時 2022-09-02 22:18:20
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,194 ms / 3,000 ms
コード長 1,005 bytes
コンパイル時間 1,790 ms
コンパイル使用メモリ 180,452 KB
実行使用メモリ 460,688 KB
最終ジャッジ日時 2024-04-27 21:53:38
合計ジャッジ時間 20,474 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 1 ms
6,944 KB
testcase_10 AC 3 ms
6,940 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 2 ms
6,940 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 431 ms
39,168 KB
testcase_18 AC 431 ms
39,040 KB
testcase_19 AC 425 ms
39,104 KB
testcase_20 AC 1,686 ms
343,808 KB
testcase_21 AC 1,772 ms
370,560 KB
testcase_22 AC 1,321 ms
261,392 KB
testcase_23 AC 1,290 ms
249,984 KB
testcase_24 AC 1,270 ms
249,984 KB
testcase_25 AC 1,303 ms
250,112 KB
testcase_26 AC 2,119 ms
460,688 KB
testcase_27 AC 2,194 ms
460,640 KB
testcase_28 AC 429 ms
39,168 KB
testcase_29 AC 1,801 ms
388,060 KB
testcase_30 AC 391 ms
36,224 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