結果
問題 | No.460 裏表ちわーわ |
ユーザー | horizon4096 |
提出日時 | 2018-01-11 13:29:41 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 29 ms / 2,000 ms |
コード長 | 1,872 bytes |
コンパイル時間 | 788 ms |
コンパイル使用メモリ | 72,204 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-08-25 10:49:43 |
合計ジャッジ時間 | 3,161 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 11 ms
4,376 KB |
testcase_01 | AC | 8 ms
4,376 KB |
testcase_02 | AC | 19 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 29 ms
4,380 KB |
testcase_06 | AC | 27 ms
4,380 KB |
testcase_07 | AC | 27 ms
4,380 KB |
testcase_08 | AC | 27 ms
4,376 KB |
testcase_09 | AC | 12 ms
4,376 KB |
testcase_10 | AC | 26 ms
4,380 KB |
testcase_11 | AC | 28 ms
4,376 KB |
testcase_12 | AC | 29 ms
4,380 KB |
testcase_13 | AC | 29 ms
4,376 KB |
testcase_14 | AC | 28 ms
4,376 KB |
testcase_15 | AC | 28 ms
4,376 KB |
testcase_16 | AC | 27 ms
4,376 KB |
testcase_17 | AC | 27 ms
4,376 KB |
testcase_18 | AC | 28 ms
4,380 KB |
testcase_19 | AC | 29 ms
4,376 KB |
testcase_20 | AC | 28 ms
4,376 KB |
testcase_21 | AC | 28 ms
4,376 KB |
testcase_22 | AC | 28 ms
4,380 KB |
testcase_23 | AC | 27 ms
4,376 KB |
testcase_24 | AC | 29 ms
4,380 KB |
testcase_25 | AC | 5 ms
4,376 KB |
testcase_26 | AC | 5 ms
4,380 KB |
testcase_27 | AC | 7 ms
4,376 KB |
ソースコード
#include <stdio.h> #include <string.h> #include <iostream> #include <vector> #include <deque> #include <queue> #include <stack> #include <map> #include <string> #include <algorithm> #include <numeric> #include <utility> #include <cmath> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> pii; typedef pair<ll, int> pli; const int iinf = 1 << 29; const long long linf = 1ll << 61; #define dump(x) cerr << #x << " : " << x << '\n' #define MOD(x, y) (((y) + (x) % (y)) % (y)) int M, N; int a[8][8]; int b[8][8]; void flip(int y, int x) { int dx[] = { 0, 1, 1, 0, -1, -1, -1, 0, 1 }; int dy[] = { 0, 0, 1, 1, 1, 0, -1, -1, -1 }; for (int i = 0; i < 9; i++) { int X = x + dx[i]; int Y = y + dy[i]; if (X < 0 || X >= N || Y < 0 || Y >= M) continue; b[Y][X] = 1 - b[Y][X]; } } int main(int argc, char* argv[]) { scanf("%d%d", &M, &N); for (int i = 0; i < M; i++) { for (int j = 0; j < N; j++) { scanf("%d", &a[i][j]); } } int ans = iinf; for (int i = 0; i < (1 << 8); i++) { for (int j = 0; j < (1 << 8); j++) { int count = 0; if ((i & 1) != (j & 1)) continue; memcpy(b, a, sizeof(a)); for (int x = 0; x < N; x++) { if ((i >> x) & 1) { flip(0, x); count++; } } for (int y = 1; y < M; y++) { if ((j >> y) & 1) { flip(y, 0); count++; } } for (int y = 1; y < M; y++) { for (int x = 1; x < N; x++) { if (b[y - 1][x - 1] == 1) { flip(y, x); count++; } } } bool flag = true; for (int x = 0; x < N; x++) { if (b[M - 1][x] == 1) flag = false; } for (int y = 0; y < M; y++) { if (b[y][N - 1] == 1) flag = false; } if (flag) { ans = min(ans, count); } } } if (ans <= M * N) { printf("%d\n", ans); } else { printf("Impossible\n"); } return 0; }