結果

問題 No.1434 Make Maze
ユーザー tkmst201tkmst201
提出日時 2021-06-06 10:46:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,442 bytes
コンパイル時間 2,655 ms
コンパイル使用メモリ 209,052 KB
実行使用メモリ 8,844 KB
最終ジャッジ日時 2023-08-16 09:37:51
合計ジャッジ時間 8,363 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 23 ms
8,596 KB
testcase_03 AC 23 ms
8,844 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 7 ms
4,744 KB
testcase_16 AC 4 ms
4,380 KB
testcase_17 AC 3 ms
4,380 KB
testcase_18 AC 4 ms
4,376 KB
testcase_19 AC 13 ms
5,984 KB
testcase_20 AC 2 ms
4,384 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 9 ms
5,212 KB
testcase_25 AC 15 ms
6,808 KB
testcase_26 AC 3 ms
4,380 KB
testcase_27 AC 9 ms
5,248 KB
testcase_28 AC 3 ms
4,380 KB
testcase_29 AC 2 ms
4,380 KB
testcase_30 AC 4 ms
4,380 KB
testcase_31 AC 4 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//

int main() {
	int H, W, X;
	cin >> H >> W >> X;
	int h = (H + 1) / 2, w = (W + 1) / 2;
	if (X % 2 == 1 || (h + w) % 2 != X / 2 % 2) { puts("-1"); return 0; }
	X /= 2;
	
	bool trans = false;
	if (h % 2 == 0) {
		trans = true;
		swap(H, W);
		swap(h, w);
	}
	
	constexpr int dx[] {-1,0,1,0}, dy[] {0,-1,0,1}; // lurd ^1 で転置
	vector<int> dirs;
	
	// (h, w) = (odd, even) or (even, even)
	if (h + w - 2 > X || h * w - 1 < X || ((~(h | w) & 1) && h * w - 1 == X)) { puts("-1"); return 0; } 
	
	X -= h + w - 2;
	REP(i, (h - 1) / 2) {
		// rrr d lll d
		const int cur = min(X / 2, w - 1);
		REP(j, cur) dirs.emplace_back(2); // r
		dirs.emplace_back(3); // d
		REP(j, cur) dirs.emplace_back(0); // l
		dirs.emplace_back(3); // d
		X -= cur * 2;
	}
	if (h & 1) REP(i, w - 1) dirs.emplace_back(2); // r
	else {
		REP(i, X / 2) {
			dirs.emplace_back(3); // d
			dirs.emplace_back(2); // r
			dirs.emplace_back(1); // u
			dirs.emplace_back(2); // r
		}
		REP(i, w - 1 - X) dirs.emplace_back(2); // r
		dirs.emplace_back(3); // d
	}
	
	if (trans) {
		for (int & a : dirs) a ^= 1;
		swap(H, W);
		swap(h, w);
	}
	vector<string> ans(H, string(W, '#'));
	REP(i, h) REP(j, w) ans[i << 1][j << 1] = '.';
	vector done(H, vector<int>(W));
	done[0][0] = true;
	int y = 0, x = 0;
	for (int dir : dirs) {
		const int ny = y + dy[dir], nx = x + dx[dir];
		ans[ny][nx] = '.';
		done[ny][nx] = true;
		y += 2 * dy[dir];
		x += 2 * dx[dir];
		done[y][x] = true;
	}
	
	REP(i, H) REP(j, W) {
		REP(dir, 4) {
			int ny = i + 2 * dy[dir], nx = j + 2 * dx[dir];
			if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
			if (ans[i][j] == '#' || ans[ny][nx] == '#') continue;
			if (done[ny][nx]) continue;
			done[ny][nx] = true;
			done[i + dy[dir]][j + dx[dir]] = true;
			ans[i + dy[dir]][j + dx[dir]] = '.';
		}
	}
	
	REP(i, H) cout << ans[i] << '\n';
}
0