結果

問題 No.179 塗り分け
ユーザー alpha_virginisalpha_virginis
提出日時 2016-03-10 20:36:52
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 19 ms / 3,000 ms
コード長 1,467 bytes
コンパイル時間 1,502 ms
コンパイル使用メモリ 68,416 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 20:47:41
合計ジャッジ時間 3,369 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 11 ms
4,380 KB
testcase_09 AC 12 ms
4,380 KB
testcase_10 AC 7 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 10 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 7 ms
4,376 KB
testcase_19 AC 7 ms
4,376 KB
testcase_20 AC 11 ms
4,380 KB
testcase_21 AC 13 ms
4,376 KB
testcase_22 AC 19 ms
4,380 KB
testcase_23 AC 6 ms
4,376 KB
testcase_24 AC 12 ms
4,376 KB
testcase_25 AC 7 ms
4,376 KB
testcase_26 AC 7 ms
4,380 KB
testcase_27 AC 11 ms
4,376 KB
testcase_28 AC 7 ms
4,380 KB
testcase_29 AC 12 ms
4,380 KB
testcase_30 AC 9 ms
4,380 KB
testcase_31 AC 11 ms
4,380 KB
testcase_32 AC 8 ms
4,380 KB
testcase_33 AC 12 ms
4,380 KB
testcase_34 AC 8 ms
4,384 KB
testcase_35 AC 12 ms
4,376 KB
testcase_36 AC 2 ms
4,380 KB
testcase_37 AC 1 ms
4,376 KB
testcase_38 AC 2 ms
4,376 KB
testcase_39 AC 2 ms
4,380 KB
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 1 ms
4,380 KB
testcase_42 AC 1 ms
4,376 KB
testcase_43 AC 2 ms
4,380 KB
testcase_44 AC 3 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstring>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <stack>
#include <cassert>

int H, W;
char field[64][64];
bool checked[64][64];

bool judge(int dr, int dc) {
  for(int i = 0; i < H; ++i) {
    for(int j = 0; j < W; ++j) {
      checked[i][j] = false;
    }
  }
  for(int r = 0; r < H; ++r) {
    for(int c = 0; c < W; ++c) {
      if( field[r][c] != '#' ) continue;
      if( checked[r][c] ) continue;
      int nr = r + dr;
      int nc = c + dc;
      if( not ( 0 <= nr and nr < H and 0 <= nc and nc < W ) ) return false;
      if( field[r+dr][c+dc] != '#' ) return false;
      checked[r+dr][c+dc] = true;
    }
  }
  return true;
}

int main() {
  // step 1
  std::cin >> H >> W;
  for(int i = 0; i < H; ++i) {
    scanf("%s", field[i]);
  }

  // step 2
  bool flag = false;
  [&](){
    for(int r = 0; r < H; ++r) {
      for(int c = 0; c < W; ++c) {
        if( field[r][c] == '#' ) {
          flag = true;
          return;
        }
      }
    }
  }();
  if( not flag ) {
    std::cout << "NO" << std::endl;
    return 0;
  }

  // step 3
  bool res = false;
  [&](){
    for(int dr = -H + 1; dr < H; ++dr) {
      for(int dc = -W + 1; dc < W; ++dc) {
        if( dr == 0 and dc == 0 ) continue;
        if( judge(dr, dc) ) {
          res = true;
          return;
        }
      }
    }
  }();
  std::cout << (res ? "YES" : "NO") << std::endl;  
  
  return 0;
}

0