Submission #384845

#TimeUsernameProblemLanguageResultExecution timeMemory
384845pure_memSelotejp (COCI20_selotejp)C++14
110 / 110
83 ms492 KiB
#include <bits/stdc++.h> #define X first #define Y second #define MP make_pair #define ll long long using namespace std; const int N = 1000, INF = 1e9; const ll mod = 1e9 + 7; int n, m, dp[11][(1 << 10)]; bool a[N][10]; int main () { ios::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++){ char x; cin >> x, a[i][j] = (x != '#'); } } for(int i = 0;i <= m;i++) for(int mask = 0;mask < (1 << m);mask++) dp[i][mask] = INF; dp[m][(1 << m) - 1] = 0; for(int i = 0;i < n;i++){ for(int j = 0;j < m;j++){ for(int mask = 0;mask < (1 << m);mask++){ if(a[i][j] && !((mask >> j) & 1)) continue; int last = j - 1; if(last == -1) last = m; if(!a[i][j]){ if((mask >> j) & 1) dp[j][mask ^ (1 << j)] = min(dp[j][mask ^ (1 << j)], dp[last][mask]); else dp[j][mask] = min(dp[j][mask], dp[last][mask]); } dp[j][mask | (1 << j)] = min(dp[j][mask | (1 << j)], dp[last][mask] + !a[i][j]); int nx = j; while(nx < m && !a[i][nx] && ((mask >> nx) & 1)){ dp[nx][mask] = min(dp[nx][mask], dp[last][mask] + 1); nx++; } } } for(int mask = 0;mask < (1 << m);mask++) dp[m][mask] = dp[m - 1][mask]; for(int i = 0;i < m;i++) for(int mask = 0;mask < (1 << m);mask++) dp[i][mask] = INF; } cout << dp[m][(1 << m) - 1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...