結果

問題 No.2064 Smallest Sequence on Grid
ユーザー みここみここ
提出日時 2022-12-13 19:52:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 301 ms / 3,000 ms
コード長 1,030 bytes
コンパイル時間 869 ms
コンパイル使用メモリ 78,820 KB
実行使用メモリ 15,104 KB
最終ジャッジ日時 2024-04-25 04:12:02
合計ジャッジ時間 7,286 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 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 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 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 1 ms
5,376 KB
testcase_17 AC 152 ms
14,848 KB
testcase_18 AC 155 ms
14,848 KB
testcase_19 AC 153 ms
14,976 KB
testcase_20 AC 233 ms
14,976 KB
testcase_21 AC 243 ms
14,976 KB
testcase_22 AC 202 ms
14,976 KB
testcase_23 AC 220 ms
15,104 KB
testcase_24 AC 220 ms
14,976 KB
testcase_25 AC 218 ms
15,104 KB
testcase_26 AC 296 ms
14,976 KB
testcase_27 AC 301 ms
14,976 KB
testcase_28 AC 152 ms
14,976 KB
testcase_29 AC 247 ms
14,976 KB
testcase_30 AC 148 ms
14,336 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;
typedef pair<int, int> P;

int main()
{
    int h, w;
    cin >> h >> w;
    string s[3005];
    for(int i = 0; i < h; i++)
    {
        cin >> s[i];
    }
    cout << s[0][0];
    vector<P> v;
    v.push_back(P(0, 0));
    for(int i = 1; i < h + w - 1; i++)
    {
        char l = 'z';
        for(auto [x, y] : v)
        {
            if(x < h - 1)
            {
                l = min(l, s[x + 1][y]);
            }
            if(y < w - 1)
            {
                l = min(l, s[x][y + 1]);
            }
        }
        cout << l;
        vector<P> z;
        for(auto [x, y] : v)
        {
            if(x < h - 1 && s[x + 1][y] == l && (z.empty() || z.back().second != y))
            {
                z.push_back(P(x + 1, y));
            }
            if(y < w - 1 && s[x][y + 1] == l && (z.empty() || z.back().first != x))
            {
                z.push_back(P(x, y + 1));
            }
        }
        swap(v, z);
    }
    cout << endl;
}
0