結果

問題 No.460 裏表ちわーわ
ユーザー krotonkroton
提出日時 2016-12-10 23:45:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 544 ms
コンパイル使用メモリ 69,168 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 10:48:28
合計ジャッジ時間 3,586 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
using namespace std;
typedef long long ll;

const int INF = 114514;

int H, W;
int a[10][10], b[10][10];

int now(int i, int j){
  int res = a[i][j];
  for(int dy=-1;dy<=1;dy++)for(int dx=-1;dx<=1;dx++){
    int ii = i + dy;
    int jj = j + dx;
    if(ii < 0 || ii >= H || jj < 0 || jj >= W)continue;
    res ^= b[ii][jj];
  }
  return res;
}

int solve(int ym, int xm){
  memset(b, 0, sizeof(b));

  for(int i=0;i<H;i++)b[i][0] = (ym >> i) & 1;
  for(int j=0;j<W;j++)b[0][j] = (xm >> j) & 1;

  for(int i=1;i<H;i++){
    for(int j=1;j<W;j++){
      b[i][j] = now(i-1, j-1);
    }
  }

  int res = 0;
  for(int i=0;i<H;i++)for(int j=0;j<W;j++){
    if(now(i, j) != 0) return INF;
    res += b[i][j];
  }

  return res;
}

int main(){
  cin >> H >> W;

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin >> a[i][j];
    }
  }

  int res = INF;
  for(int ym=0;ym<1<<H;ym++)for(int xm=0;xm<1<<W;xm++){
    res = min(res, solve(ym, xm));
  }

  if (res >= INF) {
    cout << "Impossible" << endl;
  } else {
    cout << res << endl;
  }

  return 0;
}
0