結果

問題 No.179 塗り分け
ユーザー komori3komori3
提出日時 2017-09-27 03:54:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 32 ms / 3,000 ms
コード長 2,684 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 79,260 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-30 20:56:33
合計ジャッジ時間 2,695 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 32 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 9 ms
4,380 KB
testcase_11 AC 9 ms
4,376 KB
testcase_12 AC 31 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 1 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 16 ms
4,380 KB
testcase_19 AC 15 ms
4,376 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 29 ms
4,376 KB
testcase_23 AC 14 ms
4,380 KB
testcase_24 AC 28 ms
4,376 KB
testcase_25 AC 9 ms
4,380 KB
testcase_26 AC 10 ms
4,376 KB
testcase_27 AC 27 ms
4,376 KB
testcase_28 AC 8 ms
4,380 KB
testcase_29 AC 26 ms
4,376 KB
testcase_30 AC 11 ms
4,376 KB
testcase_31 AC 26 ms
4,380 KB
testcase_32 AC 20 ms
4,380 KB
testcase_33 AC 26 ms
4,376 KB
testcase_34 AC 14 ms
4,380 KB
testcase_35 AC 26 ms
4,376 KB
testcase_36 AC 1 ms
4,376 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,376 KB
testcase_41 AC 1 ms
4,376 KB
testcase_42 AC 2 ms
4,376 KB
testcase_43 AC 3 ms
4,380 KB
testcase_44 AC 4 ms
4,376 KB
testcase_45 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;

template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr;	} cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }

#define PI 3.14159265358979323846
#define EPS 1e-6
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define all(x) (x).begin(), (x).end()

bool tr(vector<string> S, int w, int h, int b)
{
	int H = S.size();
	int W = S[0].size();

	for (int y = (h < 0 ? -h : 0); y < (h < 0 ? H : H - h); y++) {
		for (int x = (w < 0 ? -w : 0); x < (w < 0 ? W : W - w); x++) {
			if (S[y][x] == '.') continue;

			if (S[y + h][x + w] == '.') return false;

			S[y][x] = S[y + h][x + w] = '.';
			b -= 2;

			if (b == 0) return true;
		}
	}

	return false;
}

int yuki0179() 
{
	int H, W, b;
	cin >> H >> W;

	vector<string> S(H);
	for (int i = 0; i < H; i++) cin >> S[i];

	//黒マスの個数
	b = 0;
	for (int y = 0; y < H; y++) {
		for (int x = 0; x < W; x++) {
			if (S[y][x] == '#') b++;
		}
	}

	//b 奇数なら false
	if (b % 2) {
		cout << "NO" << endl;
		return 0;
	}

	//横に w, 縦に h 平行移動して一致するなら true
	for (int w = - W + 1; w < W; w++) {
		for (int h = - H + 1; h < H; h++) {
			if (w == 0 && h == 0) continue;
			if (tr(S, w, h, b)) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}

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

int main()
{
	//clock_t start, end;
	//start = clock();

	yuki0179();

	//end = clock();
	//printf("%d msec.\n", end - start);

	return 0;
}
0