結果
| 問題 | No.179 塗り分け |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-06 17:21:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 462 ms / 3,000 ms |
| コード長 | 1,956 bytes |
| コンパイル時間 | 859 ms |
| コンパイル使用メモリ | 74,640 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-23 14:30:26 |
| 合計ジャッジ時間 | 7,787 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 40 |
ソースコード
#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) {
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) {
UPD;
}
if (cnt) {
return false;
}
}
}
return true;
}
int main(void){
cin >> h >> w;
REP (i, 0, h) {
cin >> s[i];
}
int bl = 0;
REP(i, 0, h) {
bl += count(s[i].begin(), s[i].end(), '#');
}
if (bl == 0) {
cout << "NO" << endl;
return 0;
}
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;
}