結果

問題 No.2064 Smallest Sequence on Grid
ユーザー koryoukoryou
提出日時 2022-09-03 15:52:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 913 ms / 3,000 ms
コード長 2,740 bytes
コンパイル時間 1,119 ms
コンパイル使用メモリ 115,472 KB
実行使用メモリ 12,572 KB
最終ジャッジ日時 2024-04-28 13:44:36
合計ジャッジ時間 11,612 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 426 ms
12,416 KB
testcase_18 AC 424 ms
12,292 KB
testcase_19 AC 423 ms
12,292 KB
testcase_20 AC 695 ms
12,544 KB
testcase_21 AC 743 ms
12,544 KB
testcase_22 AC 609 ms
12,444 KB
testcase_23 AC 659 ms
12,544 KB
testcase_24 AC 651 ms
12,572 KB
testcase_25 AC 664 ms
12,544 KB
testcase_26 AC 913 ms
12,544 KB
testcase_27 AC 898 ms
12,544 KB
testcase_28 AC 449 ms
12,272 KB
testcase_29 AC 738 ms
12,532 KB
testcase_30 AC 398 ms
11,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <string>
#include <list>
#include <cassert>
#include <numeric>
#include <cstdint>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <random>
#include <bitset>
// #include <atcoder/all>
 
using ll = long long;
using ld = long double;
using namespace std;
// using namespace atcoder;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
using Priority = priority_queue<ll, vector<ll>, greater<ll>>;// 昇順
using Priority_pair = priority_queue<P, vector<P>, greater<P>>;
// using mint_17 = modint1000000007;
// using mint = modint998244353;
 
#define mod 1000000007
#define MAX_WIDTH 60
#define MAX_HEIGHT 60
#define inf 1e9
#define INF 8e18
#define MOD 998244353
#define PI 3.141592653589793
#define rep(i, a, b) for(ll i=(a);i<(b);i++)
#define rrep(i, a, b) for(ll i=(a);i>=(b);i--)
#define fore(i, a) for(auto &i: a)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define YES(a) cout << ((a) ? "YES" : "NO") << endl
#define Yes(a) cout << ((a) ? "Yes" : "No") << endl
#define pb push_back
#define fi first
#define se second
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
#define vc vector<char>
#define vp vector<pair<ll, ll>>
#define mll map<ll, ll>
#define msl map<string, ll>
#define COUT(n) cout << (n) << endl
#define isInGrid(a, b, h, w) (0 <= (a) && (a) < (h) && 0 <= (b) && (b) < (w))
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<typename T> void uniq(T &vec){sort(all(vec)); vec.erase(unique(all(vec)), vec.end());}
int vx[] = {1, 0, -1, 0}, vy[] = {0, 1, 0, -1};
struct edge {
    ll to, cost;
};
 
ll H, W;
char S[3010][3010];
int main() {
    cin >> H >> W;
    rep(i,0,H) {
        rep(j,0,W) {
            cin >> S[i][j];
        }
    }

    string ans;
    ans += S[0][0];
    vector<P> p = {P(0,0)};
    rep(i,0,H+W-2) {
        vector<P> nxt;
        for(auto j: p) {
            ll h = j.fi, w = j.se;
            if(h+1 < H) {
                nxt.push_back(P(h+1, w));
            }

            if(w+1 < W) {
                nxt.push_back(P(h, w+1));
            }
        }
        uniq(nxt);

        char mn = 'z';
        for(auto j: nxt) {
            if(mn > S[j.fi][j.se]) {
                mn = S[j.fi][j.se];
            }
        }
        ans += mn;
        p.clear();

        for(auto j: nxt) {
            if(S[j.fi][j.se] == mn) {
                p.push_back(j);
            }
        }
    }
    COUT(ans);
 
    return 0;
}
0