結果

問題 No.460 裏表ちわーわ
ユーザー kimiyukikimiyuki
提出日時 2016-12-12 02:00:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,316 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 75,944 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-19 17:56:55
合計ジャッジ時間 4,206 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 89 ms
4,384 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 88 ms
4,380 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 95 ms
4,384 KB
testcase_14 AC 93 ms
4,380 KB
testcase_15 AC 94 ms
4,384 KB
testcase_16 WA -
testcase_17 AC 92 ms
4,380 KB
testcase_18 AC 94 ms
4,380 KB
testcase_19 AC 93 ms
4,384 KB
testcase_20 WA -
testcase_21 AC 91 ms
4,384 KB
testcase_22 AC 92 ms
4,380 KB
testcase_23 AC 91 ms
4,380 KB
testcase_24 AC 95 ms
4,384 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_from(i,m,n) for (int i = (m); (i) < int(n); ++(i))
typedef long long ll;
using namespace std;
template <class T> void setmin(T & a, T const & b) { if (b < a) a = b; }
template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }
ll bit(int i) { return 1ll << i; }
bool is_on_field(int y, int x, int h, int w) { return 0 <= y and y < h and 0 <= x and x < w; }
const int inf = 1e9+7;
int main() {
    int h, w; cin >> h >> w;
    vector<vector<bool> > a = vectors(h, w, bool());
    repeat (y,h) repeat (x,w) {
        bool it; cin >> it;
        a[y][x] = it;
    }
    int ans = inf;
    repeat (s, bit(w)) {
        repeat (t, bit(h)) {
            int cnt = 0;
            vector<vector<bool> > b = a;
            auto flip = [&](int y, int x) {
                cnt += 1;
                repeat_from (dy,-1,1+1) repeat_from (dx,-1,1+1) {
                    int ny = y + dy;
                    int nx = x + dx;
                    if (is_on_field(ny, nx, h, w)) {
                        b[ny][nx] = not b[ny][nx];
                    }
                }
            };
            repeat (y,h) {
                repeat (x,w) {
                    if (y == 0) {
                        if (s & bit(x)) {
                            flip(y, x);
                        }
                    } else if (x == 0) {
                        if (t & bit(y-1)) {
                            flip(y, x);
                        }
                    } else {
                        if (b[y-1][x-1]) {
                            flip(y, x);
                        }
                    }
                }
            }
            bool succeeded = true;
            repeat (y,h) {
                repeat (x,w) {
                    if (b[y][x]) {
                        succeeded = false;
                    }
                }
            }
            if (succeeded) {
                setmin(ans, cnt);
            }
        }
    }
    if (ans == inf) ans = -1;
    cout << ans << endl;
    return 0;
}
0