結果
| 問題 |
No.460 裏表ちわーわ
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-12-11 00:25:41 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,236 bytes |
| コンパイル時間 | 1,758 ms |
| コンパイル使用メモリ | 169,272 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-29 02:38:22 |
| 合計ジャッジ時間 | 2,698 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int h, w;
cin >> h >> w;
vector<int> a(h);
for (int i = 0; i < h; i++) {
for (int j = 0; j < w; j++) {
int t;
cin >> t;
a[i] |= t << j;
}
}
vector<int> cost(1 << w, 1e6);
for (int i = 0; i < 1 << w; i++) {
int m = 0;
int c = 0;
for (int j = 0; j < w; j++) {
if (i >> j & 1) {
c++;
if (j - 1 >= 0) {
m ^= 1 << (j - 1);
}
if (j + 1 < w) {
m ^= 1 << (j + 1);
}
m ^= 1 << j;
}
}
cost[m] = min(cost[m], c);
}
int ans = 1e6;
for (int ii = 0; ii < 1 << w; ii++) {
int c = cost[ii];
int prev = a[0] ^ ii;
int next = ii;
for (int i = 1; i < h; i++) {
int curr = a[i] ^ next;
next = prev;
c += cost[next];
prev = curr ^ next;
}
if (prev == 0) {
ans = min(ans, c);
}
}
if (ans >= 1e6) {
puts("Impossible");
} else {
cout << ans << endl;
}
}