結果

問題 No.2064 Smallest Sequence on Grid
ユーザー やうやう
提出日時 2022-09-02 22:13:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 938 bytes
コンパイル時間 1,999 ms
コンパイル使用メモリ 185,456 KB
実行使用メモリ 39,400 KB
最終ジャッジ日時 2024-04-27 21:49:18
合計ジャッジ時間 25,002 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 4 ms
6,944 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 AC 521 ms
38,656 KB
testcase_18 AC 439 ms
38,528 KB
testcase_19 AC 450 ms
38,528 KB
testcase_20 AC 2,732 ms
39,284 KB
testcase_21 AC 2,911 ms
39,320 KB
testcase_22 AC 2,046 ms
39,036 KB
testcase_23 AC 2,116 ms
39,372 KB
testcase_24 AC 2,129 ms
39,400 KB
testcase_25 AC 2,113 ms
39,368 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 465 ms
38,656 KB
testcase_29 TLE -
testcase_30 AC 405 ms
35,456 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]);
    set<P> s; s.insert(P(0,0));
    while(t.size()<h+w+1){
        vector<V> b(0,V(3));
        while(s.size()){
            P p=*s.begin();
            int x=p.first,y=p.second;
            if(x+1<h) b.push_back(V{a[x+1][y],x+1,y});
            if(y+1<w) b.push_back(V{a[x][y+1],x,y+1});
            s.erase(s.begin());
        }
        if(b.size()==0) break;
        sort(b.begin(),b.end());
        t+=(char)('a'+b[0][0]);
        rep(i,b.size()) if(b[i][0]==b[0][0]) s.insert(P(b[i][1],b[i][2]));
    }

    cout << t << endl;

}
0