結果

問題 No.2064 Smallest Sequence on Grid
ユーザー square1001square1001
提出日時 2022-09-02 21:26:21
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 522 ms / 3,000 ms
コード長 936 bytes
コンパイル時間 644 ms
コンパイル使用メモリ 73,836 KB
実行使用メモリ 50,220 KB
最終ジャッジ日時 2023-08-10 03:15:40
合計ジャッジ時間 8,827 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,376 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,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 352 ms
49,976 KB
testcase_18 AC 350 ms
49,972 KB
testcase_19 AC 350 ms
50,044 KB
testcase_20 AC 477 ms
50,220 KB
testcase_21 AC 487 ms
50,052 KB
testcase_22 AC 442 ms
50,020 KB
testcase_23 AC 437 ms
49,972 KB
testcase_24 AC 433 ms
50,016 KB
testcase_25 AC 438 ms
50,012 KB
testcase_26 AC 522 ms
49,972 KB
testcase_27 AC 522 ms
50,112 KB
testcase_28 AC 350 ms
49,980 KB
testcase_29 AC 434 ms
44,240 KB
testcase_30 AC 318 ms
46,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <string>
#include <vector>
#include <iostream>
using namespace std;

int main() {
	int H, W;
	cin >> H >> W;
	vector<string> S(H);
	for (int i = 0; i < H; i++) {
		cin >> S[i];
	}
	vector<vector<int> > f(H, vector<int>(W, 0));
	f[0][0] = 1;
	string answer(1, S[0][0]);
	for (int i = 0; i < H + W - 2; i++) {
		char minch = '~';
		for (int x = 0; x < H; x++) {
			int y = i - x;
			if (!(0 <= y && y < W)) {
				continue;
			}
			if (f[x][y] == 1) {
				if (x != H - 1) {
					minch = min(minch, S[x + 1][y]);
				}
				if (y != W - 1) {
					minch = min(minch, S[x][y + 1]);
				}
			}
		}
		for (int x = 0; x < H; x++) {
			int y = i - x;
			if (!(0 <= y && y < W)) {
				continue;
			}
			if (f[x][y] == 1) {
				if (x != H - 1 && S[x + 1][y] == minch) {
					f[x + 1][y] = 1;
				}
				if (y != W - 1 && S[x][y + 1] == minch) {
					f[x][y + 1] = 1;
				}
			}
		}
		answer += minch;
	}
	cout << answer << endl;
	return 0;
}
0