結果
| 問題 |
No.179 塗り分け
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-02-24 21:24:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,314 bytes |
| コンパイル時間 | 842 ms |
| コンパイル使用メモリ | 72,316 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-07-23 14:55:29 |
| 合計ジャッジ時間 | 2,522 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 6 |
| other | AC * 39 WA * 1 |
ソースコード
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#define FOR(i_type, i, i_min, i_max) for(i_type i = (i_min); i < (i_max); ++i)
using namespace std;
typedef vector<vector<bool>> Grid;
bool test_trans(vector<vector<bool>> grid /*copy*/, long i, long j, size_t blacks) {
// 黒いマスを消す
FOR (long, ii, 0, grid.size() - i) {
FOR(long, jj, j > 0 ? 0 : -j, grid[0].size() - (j > 0 ? j : 0)) {
if (grid[ii][jj]) {
auto const dest = grid.at(ii + i).at(jj + j);
if (dest) {
grid[ii+i][jj+j] = 0;
blacks-=2;
}
else {
return false;
}
}
}
}
return blacks == 0;
}
int main(void) {
int H, W;
cin >> H >> W;
// 入力データを読み込む
Grid grid(H, vector<bool>(W, false));
size_t blacks = 0;
FOR (size_t, i, 0, H) {
string line;
cin >> line;
FOR(size_t, j, 0, W) {
if (line[j] == '#') {
grid[i][j] = true;
blacks++;
}
}
}
bool ok = false;
if (blacks == 0 or blacks & 1) ok = false;
else {
// Test all possible translations
FOR(size_t, i, 0, H) {
FOR (long, j, -W + 1, W) {
if ((i != 0 or j != 0) and /* 平行移動していないからスキップ */
(ok |= test_trans(grid, i, j, blacks))) break;
}
}
}
cout << (ok ? "YES" : "NO") << endl;
return 0;
}