結果

問題 No.179 塗り分け
ユーザー highdhighd
提出日時 2016-10-26 16:19:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 39 ms / 3,000 ms
コード長 3,711 bytes
コンパイル時間 508 ms
コンパイル使用メモリ 67,288 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 20:51:40
合計ジャッジ時間 2,364 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 16 ms
4,376 KB
testcase_09 AC 21 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 22 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 22 ms
4,376 KB
testcase_23 AC 1 ms
4,376 KB
testcase_24 AC 21 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 18 ms
4,376 KB
testcase_27 AC 32 ms
4,376 KB
testcase_28 AC 22 ms
4,380 KB
testcase_29 AC 38 ms
4,376 KB
testcase_30 AC 28 ms
4,380 KB
testcase_31 AC 39 ms
4,376 KB
testcase_32 AC 11 ms
4,380 KB
testcase_33 AC 36 ms
4,380 KB
testcase_34 AC 26 ms
4,380 KB
testcase_35 AC 38 ms
4,376 KB
testcase_36 AC 1 ms
4,376 KB
testcase_37 AC 1 ms
4,380 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,376 KB
testcase_40 AC 1 ms
4,380 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 1 ms
4,380 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 5 ms
4,380 KB
testcase_45 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
//#define DEBUG 0
int main() {
	enum class State{
		None,Red,Blue,Undefined
	};
	int height, width;
	std::cin >> height >> width;
	std::string l;
	std::getline(std::cin, l);
	State map[50][50];
	int cell_count = 0;
	for (int y = 0; y < height; y++) {
		std::string line;
		std::getline(std::cin, line);
		for (int x = 0; x < width; x++) {
			if (line[x] == '.') {
				map[x][y] = State::None;
			} else {
				cell_count++;
				map[x][y] = State::Undefined;
			}
		}
	}
	if (cell_count == 0 || cell_count % 2 == 1) {
		std::cout << "NO" << std::endl;
		return 0;
	}
	bool is_find=false;
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (x != 0 || y != 0) {
				is_find=true;
				int blue_count = 0;
				int red_count = 0;
				State map_copy[50][50];
#ifdef DEBUG
				std::cout << x << "," << y << std::endl;
#endif
				for (int y1 = 0; y1 < height; y1++) {
					for (int x1 = 0; x1 < width; x1++) {
						map_copy[x1][y1] = map[x1][y1];
					}
				}
				for (int y_add = 0; y_add < height; y_add++) {
					for (int x_add = 0; x_add < width; x_add++) {
						if (map_copy[x_add][y_add] == State::None) {

						}else if (x_add - x < 0 || y_add - y < 0) {
							blue_count++;
							map_copy[x_add][y_add] = State::Blue;
							if (blue_count * 2 > cell_count) {
								is_find = false;
								break;
							}
						} else if (map_copy[x_add - x][y_add - y] == State::Blue) {
							red_count++;
							map_copy[x_add][y_add] = State::Red;
						} else {
							blue_count++;
							map_copy[x_add][y_add] = State::Blue;
						}
#ifdef DEBUG
						for (int y1 = 0; y1 < height; y1++) {
							for (int x1 = 0; x1 < width; x1++) {
								std::cout << (int)map_copy[x1][y1];
							}
							std::cout << std::endl;
						}
						std::cout << std::endl;

#endif // DEBUG
					}
				}
#ifdef DEBUG
				std::cout << cell_count << ":" << red_count << ":" << blue_count << std::endl;
#endif // DEBUG
				if (is_find == true&&blue_count + red_count == cell_count&&red_count==blue_count) {
					goto loop1_end;
				} else {
					is_find = false;
				}
			}
		}
	}
	for (int y = 0; y < height; y++) {
		for (int x = 0; x < width; x++) {
			if (x != 0 || y != 0) {
				is_find = true;
				int blue_count = 0;
				int red_count = 0;
				State map_copy[50][50];
				for (int y1 = 0; y1 < height; y1++) {
					for (int x1 = 0; x1 < width; x1++) {
						map_copy[x1][y1] = map[x1][y1];
					}
				}
#ifdef DEBUG
				std::cout << x << "," << -y << std::endl;

#endif // DEBUG
				for (int y_add = height-1; y_add >= 0; y_add--) {
					for (int x_add = 0; x_add < width; x_add++) {
						if (map_copy[x_add][y_add] == State::None) {

						} else if (x_add - x < 0 || y_add + y > height) {
							blue_count++;
							map_copy[x_add][y_add] = State::Blue;
							if (blue_count * 2 > cell_count) {
								is_find = false;
								break;
							}
						} else if (map_copy[x_add - x][y_add + y] == State::Blue) {
							red_count++;
							map_copy[x_add][y_add] = State::Red;
						} else {
							blue_count++;
							map_copy[x_add][y_add] = State::Blue;
						}
#ifdef DEBUG
						for (int y1 = 0; y1 < height; y1++) {
							for (int x1 = 0; x1 < width; x1++) {
								std::cout<<(int)map_copy[x1][y1];
							}
							std::cout << std::endl;
						}
						std::cout << std::endl;
#endif // DEBUG
					}
				}
#ifdef DEBUG
				std::cout << cell_count << ":" << red_count << ":" << blue_count << std::endl;
#endif // DEBUG
				if (is_find == true && blue_count + red_count == cell_count&&red_count == blue_count) {
					goto loop1_end;
				} else {
					is_find = false;
				}
			}
		}
	}
	loop1_end:
	std::cout << (is_find ? "YES" : "NO") << std::endl;
}
0