Submission #684462

#TimeUsernameProblemLanguageResultExecution timeMemory
684462vjudge1Selotejp (COCI20_selotejp)C++17
110 / 110
66 ms44960 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int INF = 2e9; int main() { int n, m; cin>>n>>m; vector<string> grid(n); vector<vector<vector<int>>> dp(n + 1, vector<vector<int>>(m + 1, vector<int>((1<<m), INF))); for(auto& i : grid) cin>>i; for (int mask = 0; mask < (1<<m); mask++) dp[0][0][mask] = 0; for(int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { for (int p = 0; p < (1<<m); p++) { if(grid[i][j] == '.'){ dp[i][j + 1][p] = min(dp[i][j + 1][p], dp[i][j][p]); dp[i][j + 1][p ^ (1<<j)] = min(dp[i][j + 1][p ^ (1<<j)], dp[i][j][p]); }else{ int q = p | (1<<j); int v = 1 - (i && grid[i - 1][j] == '#' && (p & (1<<j))); dp[i][j + 1][q] = min(dp[i][j + 1][q], dp[i][j][p] + v); q ^= (1<<j); int h = 1 - (j && grid[i][j - 1] == '#' && !(p & (1<<(j - 1)))); dp[i][j + 1][q] = min(dp[i][j + 1][q], dp[i][j][p] + h); } } } for (int p = 0; p < (1<<m); p++) dp[i + 1][0][p] = dp[i][m][p]; } cout << *min_element(dp[n][0].begin(), dp[n][0].end()) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...