結果

問題 No.179 塗り分け
ユーザー data9824data9824
提出日時 2015-05-23 12:03:57
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,602 bytes
コンパイル時間 532 ms
コンパイル使用メモリ 65,616 KB
実行使用メモリ 9,624 KB
最終ジャッジ日時 2024-04-10 12:20:18
合計ジャッジ時間 2,218 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 1 ms
6,944 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 18 ms
9,432 KB
testcase_09 WA -
testcase_10 AC 11 ms
9,568 KB
testcase_11 AC 9 ms
9,096 KB
testcase_12 AC 21 ms
9,192 KB
testcase_13 AC 2 ms
7,580 KB
testcase_14 AC 2 ms
6,944 KB
testcase_15 AC 1 ms
6,944 KB
testcase_16 AC 1 ms
6,940 KB
testcase_17 AC 2 ms
6,944 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 1 ms
6,944 KB
testcase_21 AC 2 ms
6,940 KB
testcase_22 AC 20 ms
9,424 KB
testcase_23 AC 11 ms
9,600 KB
testcase_24 AC 18 ms
9,576 KB
testcase_25 AC 5 ms
9,468 KB
testcase_26 WA -
testcase_27 AC 20 ms
9,624 KB
testcase_28 WA -
testcase_29 AC 21 ms
9,436 KB
testcase_30 WA -
testcase_31 AC 22 ms
9,504 KB
testcase_32 AC 12 ms
9,564 KB
testcase_33 AC 22 ms
9,352 KB
testcase_34 WA -
testcase_35 AC 23 ms
9,300 KB
testcase_36 AC 1 ms
6,940 KB
testcase_37 AC 2 ms
6,940 KB
testcase_38 AC 2 ms
6,940 KB
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 2 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
testcase_42 AC 2 ms
7,496 KB
testcase_43 AC 2 ms
6,940 KB
testcase_44 AC 4 ms
6,944 KB
testcase_45 AC 2 ms
6,944 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;
	}
	static bool movable[50][50][50][50]; // [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][49][49] + 1, false);
			} else {
				for (int offsetY = 0; offsetY < h; ++offsetY) {
					for (int offsetX = 0; offsetX < w; ++offsetX) {
						movable[x][y][offsetX][offsetY]
							= (x + offsetX < w)
							&& (y + offsetY < h)
							&& (s[y + offsetY][x + offsetX] == '#');
					}
				}
			}
		}
	}
	for (int offsetY = 0; offsetY < h; ++offsetY) {
		for (int offsetX = 0; offsetX < w; ++offsetX) {
			int movableCount = 0;
			for (int y = 0; y < h; ++y) {
				for (int x = 0; x < w; ++x) {
					if (movable[x][y][offsetX][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][offsetX][offsetY]
							&& movable[x + offsetX][y + offsetY][offsetX][offsetY]) {
							overlapped = true;
						}
					}
				}
				if (!overlapped) {
					cout << "YES" << endl;
					return 0;
				}
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0