結果

問題 No.2064 Smallest Sequence on Grid
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2022-09-02 21:51:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 483 ms / 3,000 ms
コード長 1,388 bytes
コンパイル時間 1,123 ms
コンパイル使用メモリ 106,228 KB
実行使用メモリ 16,284 KB
最終ジャッジ日時 2023-08-10 03:50:12
合計ジャッジ時間 7,871 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 164 ms
15,948 KB
testcase_18 AC 163 ms
15,952 KB
testcase_19 AC 164 ms
15,904 KB
testcase_20 AC 378 ms
16,104 KB
testcase_21 AC 404 ms
16,284 KB
testcase_22 AC 311 ms
16,056 KB
testcase_23 AC 324 ms
15,952 KB
testcase_24 AC 321 ms
15,968 KB
testcase_25 AC 327 ms
15,948 KB
testcase_26 AC 482 ms
16,144 KB
testcase_27 AC 483 ms
16,008 KB
testcase_28 AC 163 ms
16,024 KB
testcase_29 AC 396 ms
15,768 KB
testcase_30 AC 149 ms
15,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <random>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)

template<class T>
using vi = vector<T>;

template<class T>
using vii = vector<vi<T>>;

template<class T>
using viii = vector<vii<T>>;

using pii = pair<int, int>;

struct status {
    int x, y;
};

int main()
{
    int h, w;
    cin >> h >> w;
    vi<string> s(h);
    rep(i, h) cin >> s[i];

    queue<status> q;
    q.push({ 0, 0 });
    char c = s[0][0];
    cout << c;

    vii<bool> visited(h, vi<bool>(w));
    const int dx[2] = { 1, 0 };
    const int dy[2] = { 0, 1 };
    for (int sm = 0; sm < h + w - 2; sm++) {
        char nc = 'z';
        while (!q.empty() && q.front().x + q.front().y == sm) {
            status v = q.front();
            q.pop();
            if (s[v.x][v.y] != c) continue;
            if (visited[v.x][v.y]) continue;
            visited[v.x][v.y] = true;
            rep(i, 2) {
                int nx = v.x + dx[i];
                int ny = v.y + dy[i];
                if (nx >= h || ny >= w) continue;
                if (s[nx][ny] <= nc) {
                    q.push({ nx, ny });
                    nc = s[nx][ny];
                }
            }
        }
        c = nc;
        cout << c;
    }
    cout << endl;

    return 0;
}
0