結果
| 問題 |
No.179 塗り分け
|
| コンテスト | |
| ユーザー |
data9824
|
| 提出日時 | 2015-05-24 10:47:20 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 3,000 ms |
| コード長 | 1,751 bytes |
| コンパイル時間 | 676 ms |
| コンパイル使用メモリ | 66,940 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-23 14:29:42 |
| 合計ジャッジ時間 | 1,845 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 40 |
ソースコード
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
vector<string> s(h);
int blackCount = 0;
for (int i = 0; i < h; ++i) {
cin >> s[i];
blackCount += count(s[i].begin(), s[i].end(), '#');
}
if (blackCount == 0) {
cout << "NO" << endl;
return 0;
}
vector<string> filled(h);
for (int offsetY = 0; offsetY < h; ++offsetY) {
for (int offsetX = 0; offsetX < w; ++offsetX) {
if (offsetX == 0 && offsetY == 0) {
continue;
}
filled.assign(s.begin(), s.end());
bool possible = true;
for (int y = 0; y < h && possible; ++y) {
for (int x = 0; x < w && possible; ++x) {
if (filled[y][x] == '#') {
if ((x + offsetX < w)
&& (y + offsetY < h)
&& (filled[y + offsetY][x + offsetX] == '#')) {
filled[y][x] = 'R';
filled[y + offsetY][x + offsetX] = 'B';
} else {
possible = false;
}
}
}
}
if (possible) {
cout << "YES" << endl;
return 0;
}
}
}
for (int offsetY = 0; offsetY < h; ++offsetY) {
for (int offsetX = 0; offsetX > -w; --offsetX) {
if (offsetX == 0 && offsetY == 0) {
continue;
}
filled.assign(s.begin(), s.end());
bool possible = true;
for (int y = 0; y < h && possible; ++y) {
for (int x = w - 1; x >= 0 && possible; --x) {
if (filled[y][x] == '#') {
if ((x + offsetX >= 0)
&& (y + offsetY < h)
&& (filled[y + offsetY][x + offsetX] == '#')) {
filled[y][x] = 'R';
filled[y + offsetY][x + offsetX] = 'B';
} else {
possible = false;
}
}
}
}
if (possible) {
cout << "YES" << endl;
return 0;
}
}
}
cout << "NO" << endl;
return 0;
}
data9824