結果

問題 No.179 塗り分け
ユーザー koba-e964
提出日時 2015-06-06 17:06:29
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
WA  
実行時間 -
コード長 1,831 bytes
コンパイル時間 751 ms
コンパイル使用メモリ 74,000 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-02 14:23:20
合計ジャッジ時間 6,455 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 39 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <cassert>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef pair<int, int> PI;
const double EPS=1e-9;
const int DEBUG = 0;

int h, w;
string s[51];
bool bl(int x, int y) {
  if (x < 0 || x >= h || y < 0 || y >= w) {
    return false;
  }
  return s[x][y] == '#';
}

int nxt(int s, bool v) {
  if (s == 0) {
    return (int)v;
  }
  if (s == 1) {
    return v ? 0 : 2;
  }
  return 2;
}

#define  UPD 	  cnt = nxt(cnt, bl(i + dx * k, j + dy * k))
bool solve(int dx, int dy) {
  if (dx == 0) {
    REP(i, 0, h) {
      REP(j, 0, dy) {
	int cnt = 0;
	REP(k, 0, (w + dy - 1) / dy) {
	  UPD;
	}
	if (cnt) {
	  return false;
	}
      }
    }
    return true;
  }
  assert(dx > 0);
  if(dy >= 0) {
    REP(j, - (dy * (h - 1)), w) {
      REP(i, 0, dx) {
	int cnt = 0;
	REP(k, 0, (h + dx - 1) / dx) {
	  UPD;
	}
	if (cnt) {
	  return false;
	}
      }
    }
    return true;
  }
  assert(dy < 0);
  REP(j, 0, w + (-dy * (h - 1))) {
    REP(i, 0, dx) {
      int cnt = 0;
      REP(k, 0, (h + dx - 1) / dx) {
	UPD;
      }
      if (cnt) {
	return false;
      }
    }
  }
  return true;
}

int main(void){
  cin >> h >> w;
  REP (i, 0, h) {
    cin >> s[i];
  }
  REP(dx, 1, h) {
    REP(dy, -w + 1, w) {
      if (solve(dx, dy)) {
	if (DEBUG) {
	  cout << "dx=" << dx << ", dy=" << dy << endl;
	}
	cout << "YES" << endl;
	return 0;
      }
    }
  }
  REP(dy, 1, w) {
    if (solve(0, dy)) {
      if (DEBUG) {
	cout << "dx=0, dy=" << dy << endl;
      }
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}
0