結果

問題 No.179 塗り分け
ユーザー masamasa
提出日時 2015-04-06 01:11:40
言語 C++11
(gcc 11.4.0)
結果
RE  
実行時間 -
コード長 1,250 bytes
コンパイル時間 683 ms
コンパイル使用メモリ 67,492 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-10 11:41:35
合計ジャッジ時間 5,228 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

using namespace std;

vector<string> board;
int h, w;

bool check(int mx, int my) {
	if (mx == 0 && my == 0) {
		return false;
	}

	auto paint = board;
	for (int i = -h; i < h; i++) {
		for (int j = -w; j < w; j++) {
			if (0 <= i + my && i + my < h && 0 <= j + mx && j + mx < w) {
				if (paint[i][j] == '#')	{
					if (board[i][j] == board[i + my][j + mx]) {
						paint[i][j] = 'A';
						paint[i+my][j+mx] = 'B';
					}
				}
			}
		}
	}

	int na = 0, nb = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			switch (paint[i][j]) {
				case 'A': na++; break;
				case 'B': nb++; break;
				case '#': return false;
				default: break;
			}
		}
	}

	return (na == nb && na > 0);
}

int main() {
	cin >> h >> w;

	board.assign(h, "");

	int n = 0;
	for (int i = 0; i < h; i++) {
		cin >> board[i];
		n += count(board[i].begin(), board[i].end(), '#');
	}

	if (n % 2 == 1) {
		cout << "NO" << endl;
		return 0;
	}

	int half = n / 2;

	for (int my = 0; my < h; my++) {
		for (int mx = 0; mx < w; mx++) {
			if (check(mx, my)) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}

	cout << "NO" << endl;
	return 0;
}
0