結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
koyopro
|
| 提出日時 | 2020-01-08 23:12:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,819 bytes |
| コンパイル時間 | 2,181 ms |
| コンパイル使用メモリ | 159,116 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-23 03:15:06 |
| 合計ジャッジ時間 | 3,674 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 20 WA * 8 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)
int dx[] = {0,1,1,0,-1,-1,-1, 0, 1};
int dy[] = {0,0,1,1, 1, 0,-1,-1,-1};
void solve();
signed main()
{
#if DEBUG
std::ifstream in("input.txt");
std::cin.rdbuf(in.rdbuf());
#endif
cin.tie(0);
ios::sync_with_stdio(false);
solve();
return 0;
}
/*================================*/
int N,M,Q;
int A[10][10], T[10][10];
int REV;
void reverse(int T[][10], int m, int n) {
REV++;
REP(i,9) {
int nm = m + dx[i];
int nn = n + dy[i];
T[nm][nn] = !T[nm][nn];
}
}
bool ok(int T[][10]) {
REP(m,M)REP(n,N) if (T[m+1][n+1]) return false;
return true;
}
void solve() {
cin>>M>>N;
REP(m,M)REP(n,N) cin>>A[m+1][n+1];
int ans = LONG_LONG_MAX;
REP(i,1<<N)REP(k,1<<(M-1)) {
REP(m,M+2)REP(n,N+2)T[m][n]=A[m][n];
REV=0;
REP(j,N) {
if (i&(1<<j)) reverse(T, 1, j+1);
}
REP(j,M-1) {
if (k%(1<<j)) reverse(T, j+2, 1);
}
REP(m,M-1)REP(n,N-1) {
if (T[m+1][n+1]) reverse(T, m+2, n+2);
}
if (ok(T)) {
// out("%lld\n", REV);
ans = min(ans, REV);
}
}
if (ans > 100) {
cout << "Impossible" << endl;
} else {
cout << ans << endl;
}
}
koyopro