結果

問題 No.179 塗り分け
ユーザー masa
提出日時 2015-04-06 01:01:16
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,200 bytes
コンパイル時間 593 ms
コンパイル使用メモリ 66,116 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 13:39:14
合計ジャッジ時間 2,108 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 35 WA * 5
権限があれば一括ダウンロードができます

ソースコード

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 = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (i + my < h && j + mx < w && 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