結果
問題 | No.460 裏表ちわーわ |
ユーザー |
![]() |
提出日時 | 2016-12-11 11:57:52 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 77 ms / 2,000 ms |
コード長 | 1,517 bytes |
コンパイル時間 | 1,733 ms |
コンパイル使用メモリ | 172,724 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-29 03:28:10 |
合計ジャッジ時間 | 3,513 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#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;elseflipped[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");elseprintf("%d\n", ans);}return 0;}