結果

問題 No.2064 Smallest Sequence on Grid
ユーザー atjh16atjh16
提出日時 2022-09-20 11:11:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 837 bytes
コンパイル時間 3,748 ms
コンパイル使用メモリ 209,560 KB
実行使用メモリ 814,776 KB
最終ジャッジ日時 2023-08-23 19:32:22
合計ジャッジ時間 8,988 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 3 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 3 ms
4,376 KB
testcase_14 AC 5 ms
4,416 KB
testcase_15 AC 4 ms
4,380 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 196 ms
44,156 KB
testcase_18 AC 202 ms
44,056 KB
testcase_19 AC 201 ms
43,960 KB
testcase_20 MLE -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int h, w;
string s[3000];
set<pair<string, int>> t[6000];

int main() {
	cin >> h >> w;

	for (int i = 0; i < h; i++)
		cin >> s[i];

	t[0].insert({s[0].substr(0, 1), 0});

	for (int k = 0; k < h + w - 2; k++) {
		if (!t[k].empty()) {
			string u = t[k].begin()->first;

			for (auto j : t[k]) {
				if (j.first != u)
					break;

				int i = j.second;

				if (i < h - 1) {
					string v = u;
					v.push_back(s[i + 1][k - i]);

					if (t[k + 1].empty() || v <= t[k + 1].begin()->first) {
						t[k + 1].insert({ v, i + 1 });
					}
				}

				if (k - i < w - 1) {
					string v = u;
					v.push_back(s[i][k - i + 1]);

					if (t[k + 1].empty() || v <= t[k + 1].begin()->first) {
						t[k + 1].insert({ v, i });
					}
				}
			}
		}
	}

	cout << t[h + w - 2].begin()->first << endl;
}
0