結果

問題 No.2064 Smallest Sequence on Grid
ユーザー やうやう
提出日時 2022-09-02 21:50:24
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 958 bytes
コンパイル時間 1,762 ms
コンパイル使用メモリ 186,544 KB
実行使用メモリ 74,368 KB
最終ジャッジ日時 2024-04-27 21:21:55
合計ジャッジ時間 25,517 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 1 ms
6,948 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 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 3 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 508 ms
73,472 KB
testcase_18 AC 469 ms
73,856 KB
testcase_19 AC 457 ms
73,728 KB
testcase_20 AC 2,734 ms
74,368 KB
testcase_21 AC 2,970 ms
74,356 KB
testcase_22 AC 2,017 ms
74,124 KB
testcase_23 AC 2,114 ms
74,288 KB
testcase_24 AC 2,064 ms
74,368 KB
testcase_25 AC 2,068 ms
74,288 KB
testcase_26 TLE -
testcase_27 TLE -
testcase_28 AC 466 ms
73,728 KB
testcase_29 AC 2,977 ms
63,232 KB
testcase_30 AC 428 ms
67,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using P=pair<ll,ll>;
using V=vector<ll>;
#define rep(i,n) for(ll i=0;i<n;i++)
#define REP(i,n) for(ll 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));
        for(auto i=s.begin();i!=s.end();++i){
            P p=*i;
            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});
        }
        if(b.size()==0) break;
        while(s.size()) s.erase(s.begin());
        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