結果

問題 No.179 塗り分け
ユーザー startcppstartcpp
提出日時 2015-04-06 00:17:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 10 ms / 3,000 ms
コード長 2,033 bytes
コンパイル時間 525 ms
コンパイル使用メモリ 74,680 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-30 20:36:28
合計ジャッジ時間 2,140 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

//形は複雑になり得るので、平行移動量を全探索しよう。
//平行移動を全探索すると…、一色を塗った時にもう一色をどこに塗るべきかが分かる
//あ、そうそう…色はちゃんと区別しないとだめだから!むやみやたらに#を
//片方の色で塗っていって、もう片方でも塗れるかとかやったらだめだから!
//これはWA解かな?(貪欲に左上から赤で塗って、平行移動先を青で塗っている感じだけど)
//って、マイナス方向!!'.'マスのみの時!!(泣
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<cstdio>
#include<cstring>
#include<cstring>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;

int h, w;
char s[50][52];	//#は濡れる

bool trans(int i, int j) {
	int data[50][50] = {0};
	int y, x;
	//cout << "i = " << i << " " << " j = " << j << endl;
	for( y = 0; y < h; y++ ) {
		for( x = 0; x < w; x++ ) {
			if ( s[y][x] == '#' && data[y][x] == 0 ) {
				if (  y + i < 0 || y + i >= h || x + j < 0 || x + j >= w ) {
					//cout << "WA1" << endl;
					return false;
				}
				if ( s[y+i][x+j] != '#' ) {
					//cout << "WA2" << endl;
					return false;
				}
				data[y][x]++;
				data[y+i][x+j]++;
			}
		}
	}
	
	for( y = 0; y < h; y++ ) {
		for( x = 0; x < w; x++ ) {
			if ( s[y][x] == '#' ) {
				if ( data[y][x] != 1 ) {
					//cout << "WA3" << endl;
					return false;
				}
			}
		}
	}
	return true;
}

signed main() {
	int i, j;
	
	cin >> h >> w;
	for( i = 0; i < h; i++ ) cin >> s[i];
	
	int cnt = 0;
	for( i = 0; i < h; i++ )
		for( j = 0; j < w; j++ )
			cnt += ( s[i][j] == '#' );
	if ( cnt == 0 || cnt%2 == 1 ) {
		cout << "NO" << endl;
		return 0;
	}
	
	for( i = 0; i < h; i++ ) {
		for( j = 0; j < w; j++ ) {
			if ( trans(i, j) || trans(-i, -j) || trans(-i, j) || trans(i, -j) ) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
	return 0;
}
0