結果

問題 No.460 裏表ちわーわ
ユーザー hirokazu1020hirokazu1020
提出日時 2016-12-11 01:05:31
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 1,401 bytes
コンパイル時間 717 ms
コンパイル使用メモリ 93,692 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 10:56:56
合計ジャッジ時間 2,541 ms
ジャッジサーバーID
(参考情報)
judge9 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS
#include<sstream>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())



int n, m;
int b[8][8];

int dy[] = { 0,-1,0,1,0 ,1,1,-1,-1 };
int dx[] = { 0,0,-1,0,1 ,1,-1,1,-1 };

void put(int y,int x,int a[][8]) {
	rep(k, 9) {
		int ny = y + dy[k];
		int nx = x + dx[k];
		if (0 <= nx&&nx<m && 0 <= ny&&ny<n) {
			a[ny][nx] ^= 1;
		}
	}
}


int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	cin >> n >> m;
	rep(i,n) {
		rep(j, m) {
			cin >> b[i][j];
		}
	}


	int ans = INF;
	rep(i, 1 << n+m - 1) {
		int c[8][8];
		memcpy(c, b, sizeof(c));
		int cnt = 0;
		rep(j, n+m-1) if(i>>j&1){
			cnt++;
			if (j < m)put(0, j, c);
			else put(j - m + 1, 0, c);
		}
		rep(y, n-1)rep(x,m-1)if(c[y][x]) {
			cnt++;
			put(y + 1, x + 1, c);
		}
		bool ok = true;
		rep(y, n)rep(x, m)if (c[y][x])ok = false;
		if (ok)ans = min(ans, cnt);
	}

	if (ans == INF)cout << "Impossible" << endl;
	else cout << ans << endl;

	return 0;
}
0