結果

問題 No.460 裏表ちわーわ
ユーザー antaanta
提出日時 2016-12-11 11:57:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 1,517 bytes
コンパイル時間 1,432 ms
コンパイル使用メモリ 170,968 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 11:19:35
合計ジャッジ時間 4,383 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 74 ms
4,380 KB
testcase_06 AC 81 ms
4,380 KB
testcase_07 AC 81 ms
4,384 KB
testcase_08 AC 81 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 82 ms
4,380 KB
testcase_11 AC 81 ms
4,380 KB
testcase_12 AC 80 ms
4,384 KB
testcase_13 AC 82 ms
4,376 KB
testcase_14 AC 82 ms
4,376 KB
testcase_15 AC 82 ms
4,384 KB
testcase_16 AC 80 ms
4,376 KB
testcase_17 AC 82 ms
4,380 KB
testcase_18 AC 82 ms
4,380 KB
testcase_19 AC 82 ms
4,380 KB
testcase_20 AC 81 ms
4,380 KB
testcase_21 AC 81 ms
4,380 KB
testcase_22 AC 82 ms
4,380 KB
testcase_23 AC 80 ms
4,376 KB
testcase_24 AC 75 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if(x < y) x = y; }

int main() {
	int H; int W;
	while(~scanf("%d%d", &H, &W)) {
		vector<vector<int> > A(H, vector<int>(W));
		for(int i = 0; i < H; ++ i) for(int j = 0; j < W; ++ j)
			scanf("%d", &A[i][j]);
		int ans = INF;
		vector<vector<int>> flipped(H, vector<int>(W));
		rep(s, 1 << (H + W - 1)) {
			rep(i, H)
				flipped[i][0] = s >> i & 1;
			rep(j, W - 1)
				flipped[0][1 + j] = s >> (H + j) & 1;
			bool ok = true;
			rer(i, 1, H) rer(j, 1, W) {
				int x = A[i - 1][j - 1];
				rer(dy, -1, 1) rer(dx, -1, 1) if(!(dy == 1 && dx == 1)) {
					int yy = i - 1 + dy, xx = j - 1 + dx;
					if(0 <= yy && yy < H && 0 <= xx && xx < W)
						x ^= flipped[yy][xx];
				}
				if(i >= H || j >= W)
					ok &= x == 0;
				else 
					flipped[i][j] = x;
			}
			if(ok) {
				int cnt = 0;
				rep(i, H) rep(j, W)
					cnt += flipped[i][j];
				amin(ans, cnt);
			}
		}
		if(ans == INF)
			puts("Impossible");
		else
			printf("%d\n", ans);
	}
	return 0;
}
0