# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
377449 | NONAME | Selotejp (COCI20_selotejp) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int_fast32_t n, m;
int_fast32_t dp[2][1 << 11];
char a[1000][10];
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
cin >> a[i][j];
}
}
int tp = 0;
for (int i : {0, 1}) {
for (int msk = 0; msk < (1 << m); ++msk) {
dp[i][msk] = 1e9;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
int nt = tp ^ 1;
for (int msk = 0; msk < (1 << m); ++msk) {
if (!((msk >> j) & 1)) {
int c = 0;
if ((a[i][j] == '#') && (!j || (a[i][j - 1] == '.') || ((msk >> (j - 1)) & 1))) {
c = 1;
}
dp[nt][msk] = min(dp[tp][msk], dp[tp][msk ^ (1 << j)]) + c;
} else {
if (a[i][j] == '.') {
dp[nt][msk] = 1e9;
} else {
dp[nt][msk] = min(dp[tp][msk], dp[tp][msk ^ (1 << j)] + 1);
}
}
}
tp ^= 1;
}
}
int ans = 1e9;
for (int msk = 0; msk < (1 << m); ++msk) {
ans = min(ans, dp[tp][msk]);
}
cout << ans << "\n";
return 0;
}