結果

問題 No.460 裏表ちわーわ
ユーザー imulanimulan
提出日時 2016-12-11 03:09:56
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 45 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 1,656 ms
コンパイル使用メモリ 170,340 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-19 11:04:20
合計ジャッジ時間 3,662 ms
ジャッジサーバーID
(参考情報)
judge13 / judge9
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<vi> vvi;

const int INF=123456789;

int main()
{
    int m,n;
    scanf(" %d %d", &m, &n);

    vvi a(m,vi(n));
    rep(i,m)rep(j,n) scanf(" %d", &a[i][j]);

    #define IN(x,y) (0<=x && x<n && 0<=y && y<m)
    int ans=INF;
    rep(mask,1<<(n+m-1))
    {
        vvi b(a);

        int ct=0;
        rep(i,n)if((mask>>i)&1)
        {
            ++ct;
            for(int x=i-1; x<=i+1; ++x)for(int y=-1; y<=1; ++y)if(IN(x,y)) b[y][x] = !b[y][x];
        }
        for(int i=1; i<m; ++i)if((mask>>(n+i-1))&1)
        {
            ++ct;
            for(int x=-1; x<=1; ++x)for(int y=i-1; y<=i+1; ++y)if(IN(x,y)) b[y][x] = !b[y][x];

        }

        for(int i=1; i<m; ++i)for(int j=1; j<n; ++j)if(b[i-1][j-1])
        {
            ++ct;
            for(int x=j-1; x<=j+1; ++x)for(int y=i-1; y<=i+1; ++y)if(IN(x,y)) b[y][x] = !b[y][x];
        }

        bool all_zero=true;
        rep(i,m)rep(j,n)if(b[i][j]!=0) all_zero=false;
        if(all_zero) ans=min(ans,ct);
    }

    if(ans==INF) printf("Impossible\n");
    else printf("%d\n", ans);
    return 0;
}
0