結果

問題 No.179 塗り分け
ユーザー めうめう🎒
提出日時 2017-02-01 17:25:58
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 30 ms / 3,000 ms
コード長 1,269 bytes
コンパイル時間 809 ms
コンパイル使用メモリ 74,992 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:40:38
合計ジャッジ時間 1,904 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int h, w, how = 0;
bool hyo[51][51] = {};

bool solve(int plusx, int plusy){
	int now = 0;
	bool used[51][51] = {};
	for(int y = 0;y < h;y++){
		for(int x = 0;x < w;x++){
			if(hyo[x][y] && !used[x][y]){
				int tox = x + plusx, toy = y + plusy;
				if(tox >= w || toy >= h || tox < 0 || toy < 0) return false;
				if(!hyo[tox][toy]) return false;
				used[x][y] = true;
				used[tox][toy] = true;
				now += 2;
			}
		}
	}
	if(now == how) return true;
	return false;
}

int main() {
	cin >> h >> w;
	string str;
	for(int i = 0;i < h;i++){
		cin >> str;
		for(int j = 0;j < w;j++){
			if(str[j] == '#'){
				hyo[j][i] = true;
				how++;
			}
		}
	}
	bool ans = false;
	for(int i = -50;i < w;i++){
		for(int j = -50;j < h;j++){
			if(solve(i, j)) ans = true;
		}
	}
	if(how == 0) ans = false;
	if(ans) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}
0