結果

問題 No.2064 Smallest Sequence on Grid
ユーザー marc2825marc2825
提出日時 2022-09-02 21:46:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 2,778 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 136,780 KB
実行使用メモリ 813,056 KB
最終ジャッジ日時 2024-04-27 21:15:51
合計ジャッジ時間 4,245 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
6,940 KB
testcase_04 MLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <functional>
#include <queue>
#include <stack>
#include <list>
#include <deque>
#include <utility>
#include <numeric>
#include <set>
#include <map>
#include <complex>
#include <cctype>
#include <climits>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <time.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using uint = unsigned;
using vi = vector<int>;
using vl = vector<long>;
using vll = vector<long long>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using vvll = vector<vll>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using pii = pair<int, int>;
using pcc = pair<char, char>;
using pll = pair<ll, ll>;
using pdd = pair<ld, ld>;
using vpii = vector<pii>;
using vpll = vector<pll>;

typedef complex<double> xy_t;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

#define rep(i, n) for (ll i = 0; i < ll(n); i++)
#define repback(i, n) for (ll i = n-1; i >= 0; i--)
#define REP(i, a, b) for (ll i = a; i < ll(b); i++)
#define REPBACK(i, a, b) for (ll i = a-1; i >= ll(b); i--)
#define all(x) (x).begin(), (x).end()
#define EPS (1e-10)
#define equals(a,b) (fabs((a) - (b)) < EPS)
#define debug(x) cout << "debug:" << x << endl
#define debug2(x, y) cout << "debug:" << x << " " << y << endl

static const double pi = acos(-1.0);
const long long INFL = pow(10,18);
const long long INFLMAX = 9223372036854775807;
const int INF = pow(10,9);
const int INFMAX = 2147483647;
const int mod1 = 1000000007;
const int mod2 = 998244353;
const vi dx = {1,0,-1,0};
const vi dy = {0,1,0,-1};
const vi dx2 = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const vi dy2 = {1, 1, 0, -1, -1, -1, 0, 1, 1};

int H = 3000;
int W = 3000;
vs S(H);
vs anslist;

void dfs(int nowy, int nowx, string ans){
    ans += S[nowy][nowx];

    if(nowy == H && nowx == W){
        anslist.push_back(ans);
        return;
    }

    if(nowy == H || S[nowy+1][nowx] > S[nowy][nowx+1]){
            dfs(nowy, nowx+1, ans);
        }
    else if(nowx == W || S[nowy+1][nowx] < S[nowy][nowx+1]){
            dfs(nowy+1, nowx, ans);
        }
        
    else if(S[nowy+1][nowx] == S[nowy][nowx+1]){
            dfs(nowy, nowx+1, ans);
            dfs(nowy+1, nowx, ans);
        }
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);

    cin >> H >> W;

    rep(i,H) cin >> S[i];

    //0-indexed
    H--; W--;
    dfs(0, 0, "");

    sort(all(anslist));

    cout << anslist[0] << endl;

}
0