結果

問題 No.2064 Smallest Sequence on Grid
ユーザー maitakeshimeji6maitakeshimeji6
提出日時 2022-09-02 22:23:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,119 bytes
コンパイル時間 1,149 ms
コンパイル使用メモリ 107,516 KB
実行使用メモリ 813,576 KB
最終ジャッジ日時 2024-04-27 21:57:37
合計ジャッジ時間 4,253 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 5 ms
6,940 KB
testcase_15 AC 4 ms
6,940 KB
testcase_16 AC 5 ms
6,944 KB
testcase_17 MLE -
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 <string>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstdio>
#include <iomanip>
#include <list>

#define PI 3.14159265358979323846
#define mod 1000000007
#define pow9 1000000000
#define INF (1 << 30)

using namespace std;


int main() {
	int h, w;
	cin >> h >> w;
	vector<vector<char>> s(h, vector<char>(w));
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> s[i][j];
		}
	}

	vector<vector<int>> dp(h + 1, vector<int>(w + 1));

	vector<string> ans(h * w + 1);

	ans[1] = s[0][0];

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {

			if (i == 0 && j == 0) continue;
			else if (i == 0) {
				ans[i * w + j + 1] = ans[i * w + j] + s[i][j];
			}
			else if (j == 0) {
				ans[i * w + j + 1] = ans[(i - 1) * w + j + 1] + s[i][j];
			}

			else if (ans[(i - 1) * w + j + 1] >= ans[i * w + j]) {
				ans[i * w + j + 1] = ans[i * w + j] + s[i][j];
			}
			else {
				ans[i * w + j + 1] = ans[(i - 1) * w + j + 1] + s[i][j];
			}
		}
	}

	cout << ans[h * w] << endl;


}

0