結果

問題 No.2064 Smallest Sequence on Grid
ユーザー NAMIDAIRONAMIDAIRO
提出日時 2022-09-02 21:40:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 899 bytes
コンパイル時間 837 ms
コンパイル使用メモリ 102,580 KB
実行使用メモリ 58,244 KB
最終ジャッジ日時 2024-04-27 21:08:07
合計ジャッジ時間 6,495 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 1 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 1 ms
6,944 KB
testcase_09 AC 1 ms
6,940 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 2 ms
6,944 KB
testcase_13 AC 3 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
testcase_16 AC 3 ms
6,944 KB
testcase_17 TLE -
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 <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>>;

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

    vi<string> dp(w);
    dp[0] = s[0][0];
    for (int j = 1; j < w; j++) dp[j] = dp[j - 1] + s[0][j];
    for(int i = 1; i < h; i++) {
        vi<string> prev(w);
        swap(prev, dp);
        dp[0] = prev[0] + s[i][0];
        for (int j = 1; j < w; j++) {
            dp[j] = dp[j - 1] + s[i][j];
            string temp = prev[j] + s[i][j];
            if (temp < dp[j]) dp[j] = temp;
        }
    }
    cout << dp[w - 1] << endl;
    return 0;
}
0