結果

問題 No.179 塗り分け
ユーザー OnjoujiToki
提出日時 2023-01-07 02:56:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 145 ms / 3,000 ms
コード長 1,558 bytes
コンパイル時間 1,522 ms
コンパイル使用メモリ 128,544 KB
最終ジャッジ日時 2025-02-10 00:53:42
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

void solve() {
  int h, w;
  std::cin >> h >> w;
  std::vector<std::string> g(h);
  for (auto& s : g) std::cin >> s;
  int cnt = 0;
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (g[i][j] == '#') cnt++;
    }
  }
  if (cnt & 1 or cnt == 0) {
    std::cout << "NO\n";
    return;
  }

  for (int dx = 1 - h; dx < h; dx++) {
    for (int dy = 1 - w; dy < w; dy++) {
      if (!dx and !dy) continue;
      auto t = g;
      int c = 0;
      for (int x = 0; x < h; x++) {
        for (int y = 0; y < w; y++) {
          if (t[x][y] == '#') {
            int nx = x + dx, ny = y + dy;
            if (nx >= 0 and ny >= 0 and nx < h and ny < w and
                t[nx][ny] == '#') {
              t[x][y] = 'R';
              t[nx][ny] = 'B';
              c += 2;
            }
          }
        }
      }
      if (cnt == c) {
        std::cout << "YES" << '\n';
        return;
      }
    }
  }
  std::cout << "NO" << '\n';
}
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int t = 1;
  // std::cin >> t;
  while (t--) solve();
  // solve();
  return 0;
}
0