結果
問題 | No.179 塗り分け |
ユーザー |
|
提出日時 | 2017-09-27 03:54:52 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 34 ms / 3,000 ms |
コード長 | 2,684 bytes |
コンパイル時間 | 786 ms |
コンパイル使用メモリ | 84,788 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-07-23 14:44:15 |
合計ジャッジ時間 | 2,256 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 6 |
other | AC * 40 |
ソースコード
#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; }