結果

問題 No.2064 Smallest Sequence on Grid
ユーザー QCFiumQCFium
提出日時 2022-09-02 21:32:43
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 277 ms / 3,000 ms
コード長 801 bytes
コンパイル時間 1,665 ms
コンパイル使用メモリ 171,360 KB
実行使用メモリ 15,040 KB
最終ジャッジ日時 2023-08-10 03:26:40
合計ジャッジ時間 6,817 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 162 ms
14,988 KB
testcase_18 AC 164 ms
14,792 KB
testcase_19 AC 164 ms
14,788 KB
testcase_20 AC 238 ms
14,956 KB
testcase_21 AC 247 ms
14,924 KB
testcase_22 AC 210 ms
14,956 KB
testcase_23 AC 218 ms
15,040 KB
testcase_24 AC 218 ms
14,972 KB
testcase_25 AC 220 ms
15,040 KB
testcase_26 AC 277 ms
14,988 KB
testcase_27 AC 276 ms
14,956 KB
testcase_28 AC 162 ms
14,808 KB
testcase_29 AC 231 ms
14,920 KB
testcase_30 AC 149 ms
14,088 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

int main() {
	int h = ri();
	int w = ri();
	std::string s[h];
	for (auto &i : s) std::cin >> i;
	
	std::string res{s[0][0]};
	std::vector<int> cur = {0};
	for (int i = 1; i < h + w - 1; i++) {
		std::vector<int> xs;
		for (auto j : cur) {
			if (!xs.size() || xs.back() < j) xs.push_back(j);
			if (j + 1 < h && (!xs.size() || xs.back() < j + 1)) xs.push_back(j + 1);
		}
		char min = 'z' + 1;
		std::vector<int> mindex;
		for (auto x : xs) {
			if (i - x < 0 || i - x >= w) continue;
			if (min > s[x][i - x]) {
				min = s[x][i - x];
				mindex = {x};
			} else if (min == s[x][i - x]) mindex.push_back(x);
		}
		assert(mindex.size());
		cur = mindex;
		res.push_back(min);
	}
	std::cout << res << std::endl;
	return 0;
}
0