結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-02-15 17:01:48 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,298 bytes |
| コンパイル時間 | 1,448 ms |
| コンパイル使用メモリ | 93,856 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-12-29 23:16:57 |
| 合計ジャッジ時間 | 2,070 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 WA * 13 |
ソースコード
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;
int gauss_elim_i64(VL a, ll b) {
int n = a.size();
int c = 0;
vector<int> revmap;
REP(r, 0, 64) {
if (c >= n) {
break;
}
int c2 = -1;
REP(i, c, n) {
if (a[i] & (1LL << r)) {
c2 = i;
break;
}
}
if (c2 < 0) {
revmap.push_back(-1);
continue;
}
if (c != c2) {
swap(a[c], a[c2]);
}
ll rm = a[c] & -(1LL << r) << 1;
a[c] ^= rm;
REP(k, c + 1, n) {
if (a[k] & (1LL << r)) {
a[k] ^= rm;
}
}
if (b & (1LL << r)) {
b ^= rm;
}
revmap.push_back(c);
c++;
}
// recover
if (0) {
REP(i, 0, revmap.size()) {
cout << "revmap: " << i << " => " << revmap[i] << endl;
}
}
int rank = revmap.size();
ll x = 0;
for (int i = rank - 1; i >= 0; --i) {
if (b & 1LL << i) {
int c = revmap[i];
if (c < 0) {
return -1;
}
b ^= a[c];
x |= 1LL << c;
}
}
return b == 0 ? __builtin_popcountll(x) : -1;
}
int solve(ll board, int m, int n) {
VL basis;
REP(i, 0, m) {
REP(j, 0, n) {
ll v = 0;
REP(dx, -1, 2) {
REP(dy, -1, 2) {
int ni = i + dx;
int nj = j + dy;
if (ni < 0 || ni >= m || nj < 0 || nj >= n) {
continue;
}
v |= 1 << (ni * n + nj);
}
}
basis.push_back(v);
}
}
int rank = gauss_elim_i64(basis, board);
return rank;
}
int main(void){
int m, n;
cin >> m >> n;
ll board = 0;
REP(i, 0, m) {
REP(j, 0, n) {
int tmp;
cin >> tmp;
board |= tmp << (i * n + j);
}
}
int result = solve(board, m, n);
if (result < 0) {
cout << "Impossible" << endl;
} else {
cout << solve(board, m, n) << endl;
}
}