結果

問題 No.179 塗り分け
ユーザー kyo1
提出日時 2020-08-23 18:33:43
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 103 ms / 3,000 ms
コード長 970 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 197,484 KB
最終ジャッジ日時 2025-01-13 12:45:46
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  for (int i = 0; i < H; i++) {
    cin >> S[i];
  }
  int count = 0;
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      if (S[i][j] == '#') count++;
    }
  }
  if (count == 0) {
    cout << "NO" << '\n';
    return 0;
  }
  for (int i = 0; i < H; i++) {
    for (int j = 1 - W; j < W; j++) {
      if (i == 0 && j == 0) continue;
      auto T = S;
      int c = 0;
      for (int y = 0; y < H; y++) {
        for (int x = 0; x < W; x++) {
          if (T[y][x] != '#') continue;
          if (i + y < H && j + x >= 0 && j + x < W && T[i + y][j + x] == '#') {
            T[y][x] = T[i + y][j + x] = '.';
            c += 2;
          }
        }
      }
      if (count == c) {
        cout << "YES" << '\n';
        return 0;
      }
    }
  }
  cout << "NO" << '\n';
  return 0;
}
0