結果

問題 No.179 塗り分け
ユーザー Zhendong JiaZhendong Jia
提出日時 2019-04-12 17:26:43
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 274 ms / 3,000 ms
コード長 1,976 bytes
コンパイル時間 883 ms
コンパイル使用メモリ 96,536 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-30 21:10:23
合計ジャッジ時間 3,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>

#include <algorithm>
#include <bitset>
#include <complex>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#define SZ(a) (int)(a).size()
#define FOR(i,a,b) for (int i=(a); i<=(b); ++i)
#define REP(i,n) for (int i=0; i<(n); ++i)
#define ALL(c) c.begin(), c.end()
#define CLR(c,n) memset(c, n, sizeof(c))
#define MCPY(d, s) memcpy(d, s, sizeof(d))
#define TR(it, c) for (auto it = c.begin();it != c.end(); ++it)
#define CONTAIN(it, c) (c.find(it) != c.end())
typedef vector<int> VI;
typedef pair<int, int> PII;
template <class T> void checkmin(T &a, T b) { if (b<a) a=b; }
template <class T> void checkmax(T &a, T b) { if (b>a) a=b; }
typedef long long LL;
const int INF=0x3F3F3F3F;

PII x[2500];
int n;
#define X first
#define Y second
PII operator+(PII p, PII q) { return PII(p.X+q.X, p.Y+q.Y); }
PII operator-(PII p, PII q) { return PII(p.X-q.X, p.Y-q.Y); }

bool check(PII diff) {
  set<PII> s(x, x+n);
  while (!s.empty()) {
    PII b=*s.begin();
    int cnt = 0;
    for (PII p = b; CONTAIN(p, s); p = p + diff) {
      s.erase(p);
      ++cnt;
    }
    for (PII p = b - diff; CONTAIN(p, s); p = p - diff) {
      s.erase(p);
      ++cnt;
    }
    if (cnt % 2 == 1) return false;
  }
  return true;
}

bool go() {
  if (n % 2 == 1) return false;
  for (int i = 1; i < n; ++i) {
    if (check(x[i]-x[0])) return true;
  }
  return false;
}
int main(int argc, char *argv[]) {
  int w, h;
  char s[64];
  while (scanf("%d%d", &h, &w) == 2) {
    n = 0;
    REP(i, h) {
      scanf("%s", s);
      REP(j, w) if (s[j] == '#') x[n++] = PII(i, j);
    }
    printf("%s\n", go() ? "YES" : "NO");
  }
}
0