結果

問題 No.179 塗り分け
ユーザー Joy YehJoy Yeh
提出日時 2019-02-24 21:24:31
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,314 bytes
コンパイル時間 686 ms
コンパイル使用メモリ 73,448 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-30 21:07:18
合計ジャッジ時間 2,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 43 ms
4,380 KB
testcase_09 AC 42 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 43 ms
4,376 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,384 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 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,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 43 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 41 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 8 ms
4,376 KB
testcase_27 AC 41 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 41 ms
4,380 KB
testcase_30 AC 18 ms
4,380 KB
testcase_31 AC 41 ms
4,376 KB
testcase_32 AC 13 ms
4,376 KB
testcase_33 AC 41 ms
4,380 KB
testcase_34 AC 9 ms
4,376 KB
testcase_35 AC 41 ms
4,380 KB
testcase_36 AC 1 ms
4,380 KB
testcase_37 AC 2 ms
4,376 KB
testcase_38 AC 1 ms
4,380 KB
testcase_39 WA -
testcase_40 AC 1 ms
4,376 KB
testcase_41 AC 2 ms
4,376 KB
testcase_42 AC 2 ms
4,380 KB
testcase_43 AC 2 ms
4,376 KB
testcase_44 AC 7 ms
4,376 KB
testcase_45 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0