結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
hirokazu1020
|
| 提出日時 | 2016-12-11 01:05:31 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 41 ms / 2,000 ms |
| コード長 | 1,401 bytes |
| コンパイル時間 | 646 ms |
| コンパイル使用メモリ | 96,372 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-29 02:44:51 |
| 合計ジャッジ時間 | 2,317 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#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;
}
hirokazu1020