結果

問題 No.179 塗り分け
ユーザー ty70
提出日時 2015-04-10 17:13:41
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 3,000 ms
コード長 2,363 bytes
コンパイル時間 736 ms
コンパイル使用メモリ 91,068 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-23 14:28:39
合計ジャッジ時間 1,821 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define each(i,c) for(auto i=(c).begin();i!=(c).end();++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define clr(a) memset((a),0,sizeof(a))
#define nclr(a) memset((a),-1,sizoef(a))
#define sz(s) (int)((s).size())
#define INRANGE(x,s,e) ((s)<=(x) && (x)<(e))
#define pb push_back
#define MP(x,y) make_pair((x),(y))
#define NOCOLOR -1
#define RED 0
#define BLUE 1

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

char board[52][52];
int  color[52][52];

bool is_ok (int H, int W ){

	int cnt = 0;
	rep (i, H ) rep (j, W ) cnt += (board[i][j] == '#' );
	if (cnt == 0 || cnt == 1 ) return false; 

	rep (dy, H ){
		for (int dx = -W; dx <= W; dx++ ){
			if (dy == 0 && dx <= 0 ) continue;
			memset (color, NOCOLOR, sizeof (color ) );
			bool ok = true;
			rep (i, H ){
				rep (j, W ){
					if (board[i][j] == '#' && color[i][j] == NOCOLOR ){
						int ny = i + dy;
						int nx = j + dx;
						if (ny < 0 || ny >= H || nx < 0 || nx >= W ){
							ok = false;
							break;
						} // end if
						if (board[ny][nx] == '#' && color[ny][nx] == NOCOLOR ){
							color[i][j] = RED;
							color[ny][nx] = BLUE;
						}else{
							ok = false;
							break;
						} // end if
					} // end if
				} // end rep
				if (!ok ) break;
			} // end rep
			if (ok ){
				return true;
			} // end if
		} // end for
	} // end rep

	return false;
}

int main()
{
	memset (board, 0, sizeof (board ) );
	ios_base::sync_with_stdio(0);
	int H, W; cin >> H >> W;
	rep (i, H ) rep (j, W ) cin >> board[i][j];

	bool res = is_ok (H, W );
	cout << (res ? "YES" : "NO" ) << endl;

	return 0;
}
0