結果

問題 No.460 裏表ちわーわ
ユーザー koprickykopricky
提出日時 2017-09-13 01:15:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,350 bytes
コンパイル時間 1,198 ms
コンパイル使用メモリ 146,276 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-07 13:29:29
合計ジャッジ時間 3,191 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a,b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl
#define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl
#define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 8;
const int dx[] = {1,1,1,0,0,0,-1,-1,-1};
const int dy[] = {1,0,-1,1,0,-1,1,0,-1};

int f[MAX_N][MAX_N];
int work[MAX_N][MAX_N];
int n,m;

void paint(int u,int v)
{
    rep(i,9){
        int nu = u + dx[i],nv = v + dy[i];
        if(0 <= nu && nu < n && 0 <= nv && nv < m){
            work[nu][nv] ^= 1;
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    rep(i,n){
        rep(j,m){
            cin >> f[i][j];
        }
    }
    int ans = INF;
    rep(i,(1 << n+m-1)){
        int cnt = 0;
        rep(j,n){
            rep(k,m){
                work[j][k] = f[j][k];
            }
        }
        vector<int> vec(n+m-1,0);
        rep(j,m){
            if(i & (1 << j)){
                paint(0,j);
                cnt++;
            }
        }
        rep(j,n-1){
            if(i & (1 << (m+j))){
                paint(j+1,0);
                cnt++;
            }
        }
        for(int j=1;j<n;j++){
            for(int k=1;k<m;k++){
                if(work[j-1][k-1] == 1){
                    paint(j,k);
                    cnt++;
                }
            }
        }
        bool flag = true;
        rep(j,n){
            rep(k,n){
                if(work[j][k] == 1){
                    flag = false;
                    break;
                }
            }
            if(!flag){
                break;
            }
        }
        if(flag){
            ans = min(ans,cnt);
        }
    }
    if(ans == INF){
        cout << "Impossible\n";
    }else{
        cout << ans << endl;
    }
    return 0;
}
0