結果

問題 No.179 塗り分け
ユーザー not_522
提出日時 2015-07-30 21:39:32
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 37 ms / 3,000 ms
コード長 1,150 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 164,668 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:31:32
合計ジャッジ時間 2,795 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

bool solve(vector<string> s, int y, int x) {
  for (int i = 0; i < (int)s.size(); ++i) {
    for (int j = 0; j < (int)s[0].size(); ++j) {
      if (s[i][j] == '#') {
        s[i][j] = '.';
        if (i + y >= (int)s.size()) return false;
        if (j + x >= (int)s[0].size()) return false;
        if (s[i + y][j + x] == '.') return false;
        s[i + y][j + x] = '.';
      }
    }
  }
  return true;
}

bool solve(vector<string>& s) {
  for (int i = 0; i < (int)s.size(); ++i) {
    for (int j = 0; j < (int)s[0].size(); ++j) {
      if (solve(s, i, j)) return true;
    }
  }
  return false;
}

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for (auto& i : s) cin >> i;
  int c = 0;
  for (auto& i : s) c+= count(i.begin(), i.end(), '#');
  if (c == 0 || c % 2) {
    cout << "NO" << endl;
    return 0;
  }
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < 2; ++j) {
      if (solve(s)) {
        cout << "YES" << endl;
        return 0;
      }
      for (auto& k : s) reverse(k.begin(), k.end());
    }
    reverse(s.begin(), s.end());
  }
  cout << "NO" << endl;
}
0