結果

問題 No.179 塗り分け
ユーザー data9824data9824
提出日時 2015-05-23 12:32:39
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,789 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 67,404 KB
実行使用メモリ 28,068 KB
最終ジャッジ日時 2023-07-25 20:48:19
合計ジャッジ時間 6,846 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
5,516 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
5,688 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 22 ms
27,760 KB
testcase_09 AC 26 ms
27,860 KB
testcase_10 AC 118 ms
27,748 KB
testcase_11 AC 95 ms
26,976 KB
testcase_12 AC 256 ms
26,720 KB
testcase_13 AC 7 ms
24,100 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 294 ms
27,940 KB
testcase_23 AC 123 ms
27,808 KB
testcase_24 AC 289 ms
27,844 KB
testcase_25 AC 157 ms
27,916 KB
testcase_26 AC 146 ms
27,920 KB
testcase_27 AC 296 ms
27,740 KB
testcase_28 AC 159 ms
27,972 KB
testcase_29 AC 294 ms
28,068 KB
testcase_30 AC 119 ms
27,872 KB
testcase_31 AC 304 ms
27,856 KB
testcase_32 AC 138 ms
27,752 KB
testcase_33 AC 306 ms
27,744 KB
testcase_34 WA -
testcase_35 AC 304 ms
27,972 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 3 ms
9,604 KB
testcase_40 AC 3 ms
9,800 KB
testcase_41 AC 2 ms
4,380 KB
testcase_42 AC 4 ms
15,776 KB
testcase_43 AC 4 ms
8,692 KB
testcase_44 AC 18 ms
18,924 KB
testcase_45 AC 6 ms
15,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector<string> s(h);
	int blackCount = 0;
	for (int i = 0; i < h; ++i) {
		cin >> s[i];
		blackCount += count(s[i].begin(), s[i].end(), '#');
	}
	if (blackCount == 0 || blackCount % 2 == 1) {
		cout << "NO" << endl;
		return 0;
	}
	const int OFFSET_BASE = 50;
	static bool movable[50][50][100][100]; // [cellX][cellY][offsetX][offsetY]
	for (int y = 0; y < h; ++y) {
		for (int x = 0; x < w; ++x) {
			if (s[y][x] == '.') {
				fill(&movable[x][y][0][0], &movable[x][y][99][99] + 1, false);
			} else {
				for (int offsetY = -h; offsetY < h; ++offsetY) {
					for (int offsetX = -w; offsetX < w; ++offsetX) {
						movable[x][y][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY]
							= (0 <= x + offsetX && x + offsetX < w)
							&& (0 <= y + offsetY && y + offsetY < h)
							&& (s[y + offsetY][x + offsetX] == '#');
					}
				}
			}
		}
	}
	for (int offsetY = -h; offsetY < h; ++offsetY) {
		for (int offsetX = -w; offsetX < w; ++offsetX) {
			int movableCount = 0;
			for (int y = 0; y < h; ++y) {
				for (int x = 0; x < w; ++x) {
					if (movable[x][y][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY]) {
						++movableCount;
					}
				}
			}
			if (movableCount == blackCount / 2) {
				bool overlapped = false;
				for (int y = 0; y < h && !overlapped; ++y) {
					for (int x = 0; x < w && !overlapped; ++x) {
						if (movable[x][y][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY]
							&& movable[x + offsetX][y + offsetY][OFFSET_BASE + offsetX][OFFSET_BASE + offsetY]) {
							overlapped = true;
						}
					}
				}
				if (!overlapped) {
					cout << "YES" << endl;
					return 0;
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0