結果

問題 No.2064 Smallest Sequence on Grid
ユーザー atjh16atjh16
提出日時 2022-09-20 11:36:33
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,185 ms / 3,000 ms
コード長 768 bytes
コンパイル時間 2,211 ms
コンパイル使用メモリ 207,100 KB
実行使用メモリ 436,896 KB
最終ジャッジ日時 2023-08-23 19:33:06
合計ジャッジ時間 20,009 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 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 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 163 ms
15,560 KB
testcase_18 AC 163 ms
15,332 KB
testcase_19 AC 163 ms
15,484 KB
testcase_20 AC 1,578 ms
320,004 KB
testcase_21 AC 1,717 ms
346,808 KB
testcase_22 AC 1,191 ms
237,644 KB
testcase_23 AC 1,153 ms
226,248 KB
testcase_24 AC 1,167 ms
226,212 KB
testcase_25 AC 1,175 ms
226,208 KB
testcase_26 AC 2,185 ms
436,864 KB
testcase_27 AC 2,163 ms
436,896 KB
testcase_28 AC 164 ms
15,456 KB
testcase_29 AC 1,798 ms
369,696 KB
testcase_30 AC 152 ms
15,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

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

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

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

	t = s[0].substr(0, 1);
	u[0].insert(0);

	for (int k = 0; k < h + w - 2; k++) {
		char c = '{';

		for (int i : u[k]) {
			if (i < h - 1) {
				if (s[i + 1][k - i] < c) {
					c = s[i + 1][k - i];
					u[k + 1].clear();
					u[k + 1].insert(i + 1);
				}
				else if (s[i + 1][k - i] == c) {
					u[k + 1].insert(i + 1);
				}
			}

			if (k - i < w - 1) {
				if (s[i][k - i + 1] < c) {
					c = s[i][k - i + 1];
					u[k + 1].clear();
					u[k + 1].insert(i);
				}
				else if (s[i][k - i + 1] == c) {
					u[k + 1].insert(i);
				}
			}
		}

		t.push_back(c);
	}

	cout << t << endl;
}
0