結果
問題 | No.460 裏表ちわーわ |
ユーザー |
![]() |
提出日時 | 2020-01-08 23:28:52 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 26 ms / 2,000 ms |
コード長 | 2,114 bytes |
コンパイル時間 | 1,523 ms |
コンパイル使用メモリ | 159,600 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-23 03:15:25 |
合計ジャッジ時間 | 3,190 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 28 |
ソースコード
#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 print(int T[][10]) { REP(m,M) { REP(n,N) { cout << T[m+1][n+1]; } cout << endl; } cout << "-----" << endl; } 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]; } // out("%lld, %lld\n", m, n); // print(T); } 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]; // cout << bitset<4>(i) << " " << bitset<3>(k) << endl; // print(T); 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; } }