Submission #377434

#TimeUsernameProblemLanguageResultExecution timeMemory
377434NONAMESelotejp (COCI20_selotejp)C++17
110 / 110
60 ms512 KiB
#include <bits/stdc++.h> using namespace std; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); int n, m; int 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...