結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
horizon4096
|
| 提出日時 | 2018-01-11 13:29:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 36 ms / 2,000 ms |
| コード長 | 1,872 bytes |
| コンパイル時間 | 626 ms |
| コンパイル使用メモリ | 72,940 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-23 17:20:48 |
| 合計ジャッジ時間 | 2,464 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
コンパイルメッセージ
main.cpp: In function ‘int main(int, char**)’:
main.cpp:46:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
46 | scanf("%d%d", &M, &N);
| ~~~~~^~~~~~~~~~~~~~~~
main.cpp:49:30: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
49 | scanf("%d", &a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
#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;
}
horizon4096