結果

問題 No.179 塗り分け
ユーザー knk
提出日時 2017-09-17 18:26:44
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 87 ms / 3,000 ms
コード長 1,594 bytes
コンパイル時間 1,689 ms
コンパイル使用メモリ 170,164 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-23 14:44:19
合計ジャッジ時間 3,395 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  int h, w;
  cin >> h >> w;
  bool isb[h][w];
  int cnt = 0;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      char c;
      cin >> c;
      isb[i][j] = (c=='#' ? true : false);
      if (isb[i][j]) cnt++;
    }
  }
  if (cnt%2==1 || cnt < 2) {cout << "NO" << endl; return 0;}
  for (int i = 0; i < h; ++i) {
    for (int j = -w; j < w; ++j) {
      if (i==0 && j==0) continue;
      int f_cnt = 0;
      bool hit[h][w];
      for (int k = 0; k < h; ++k) {
        for (int l = 0; l < w; ++l) hit[k][l] = false;
      }
      for (int k = 0; k < h; ++k) {
        if (j > 0) {
          for (int l = 0; l < w; ++l) {
            if (hit[k][l]) continue;
            if (isb[k][l] && 0 <= i+k && i+k<h && 0 <= j+l && j+l<w) {
              if (isb[i+k][j+l]) {
                f_cnt++;
                hit[i+k][j+l] = true;
              }
            }
          }
        } else {
          for (int l = w-1; l >= 0; --l) {
            if (hit[k][l]) continue;
            if (isb[k][l] && 0 <= i+k && i+k<h && 0 <= j+l && j+l<w) {
              if (isb[i+k][j+l]) {
                f_cnt++;
                hit[i+k][j+l] = true;
              }
            }
          }
        }
      }
      if (f_cnt == cnt/2) {
        cerr << i << " " << j << endl;
        cout << "YES" << endl;
        return 0;
      }
    }
  }
  cout << "NO" << endl;
  return 0;
}
0