Submission #1024041

#TimeUsernameProblemLanguageResultExecution timeMemory
1024041kustizusSelotejp (COCI20_selotejp)C++17
110 / 110
37 ms40792 KiB
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); // freopen ("file.inp","r",stdin); // freopen ("file.out","w",stdout); int n, m; cin >> n >> m; vector<string> s(n); vector<vector<vector<int>>> dp(n, vector<vector<int>>(m, vector<int>(1 << m, 1e9))); for (string &x : s) cin >> x; for (int i = 0; i < n; i++) for (int j = 0; j < m; j++) for (int mask = 0; mask < (1 << m); mask++) if (mask & (1 << j)) { if (s[i][j] == '.') dp[i][j][mask] = 1e9; else if (!j) { if (!i) dp[i][j][mask] = (mask != 1 ? 1e9 : 1); else dp[i][j][mask] = min(dp[i - 1][m - 1][mask], dp[i - 1][m - 1][mask ^ (1 << j)] + 1); } else dp[i][j][mask] = min(dp[i][j - 1][mask], dp[i][j - 1][mask ^ (1 << j)] + 1); } else { if (!j) { if (!i) dp[i][j][mask] = (mask != 0 ? 1e9 : (s[i][j] == '#')); else dp[i][j][mask] = min(dp[i - 1][m - 1][mask], dp[i - 1][m - 1][mask ^ (1 << j)]) + (s[i][j] == '#'); } else { dp[i][j][mask] = min(dp[i][j - 1][mask], dp[i][j - 1][mask ^ (1 << j)]); if (s[i][j] == '#' && (!j || mask & (1 << (j - 1)) || s[i][j - 1] == '.')) dp[i][j][mask]++; } } int ans = 1e9; for (int i = 0; i < (1 << m); i++) ans = min(ans, dp[n - 1][m - 1][i]); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...