結果

問題 No.460 裏表ちわーわ
ユーザー koyoprokoyopro
提出日時 2020-01-08 23:12:12
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,819 bytes
コンパイル時間 3,173 ms
コンパイル使用メモリ 146,656 KB
実行使用メモリ 4,508 KB
最終ジャッジ日時 2023-08-15 00:51:53
合計ジャッジ時間 4,625 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define RFOR(i, a, b) for(int i=(b-1);i>=(a);i--)
#define REP(i, n) for(int i=0; i<(n); i++)
#define RREP(i, n) for(int i=(n-1); i>=0; i--)
#define ALL(a) (a).begin(),(a).end()
#define UNIQUE_SORT(l) sort(ALL(l)); l.erase(unique(ALL(l)), l.end());
#define CONTAIN(a, b) find(ALL(a), (b)) != (a).end()
#define array2(type, x, y) array<array<type, y>, x>
#define vector2(type) vector<vector<type> >
#define out(...) printf(__VA_ARGS__)

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

void solve();
signed main()
{
#if DEBUG
    std::ifstream in("input.txt");
    std::cin.rdbuf(in.rdbuf());
#endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

/*================================*/

int N,M,Q;
int A[10][10], T[10][10];
int REV;

void reverse(int T[][10], int m, int n) {
    REV++;
    REP(i,9) {
        int nm = m + dx[i];
        int nn = n + dy[i];
        T[nm][nn] = !T[nm][nn];
    }
}

bool ok(int T[][10]) {
    REP(m,M)REP(n,N) if (T[m+1][n+1]) return false;
    return true;
}

void solve() {
    cin>>M>>N;
    REP(m,M)REP(n,N) cin>>A[m+1][n+1];
    
    int ans = LONG_LONG_MAX;
    REP(i,1<<N)REP(k,1<<(M-1)) {
        REP(m,M+2)REP(n,N+2)T[m][n]=A[m][n];
        REV=0;
        REP(j,N) {
            if (i&(1<<j)) reverse(T, 1, j+1);
        }
        REP(j,M-1) {
            if (k%(1<<j)) reverse(T, j+2, 1);
        }
        REP(m,M-1)REP(n,N-1) {
            if (T[m+1][n+1]) reverse(T, m+2, n+2);
        }
        if (ok(T)) {
//            out("%lld\n", REV);
            ans = min(ans, REV);
        }
    }
    
    if (ans > 100) {
        cout << "Impossible" << endl;
    } else {
        cout << ans << endl;
    }
}
0