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;
#define ll long long
int const N=1030;
int const inf=1e9;
int dp[N],cur[N];
string s[N];
int main(){
int n,m;
cin>>n>>m;
for (int i = 1; i < N; ++i){
dp[i]=inf;
cur[i]=inf;
}
dp[0]=0;
cur[0]=inf;
for (int i = 0; i < n; ++i)
cin>>s[i];
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]=='.')
cur[mask]=inf;
else
cur[mask]=min(dp[mask],dp[mask ^ (1<<j)]+1);
}
else{
cur[mask]=min(dp[mask],dp[mask^(1<<j)]);
if(s[i][j] == '#' && (j == 0 || (mask & (1 << (j - 1))) || s[i][j - 1] == '.'))
cur[mask]++;
}
}
for (int mask = 0; mask < (1<<m); ++mask)
dp[mask]=cur[mask];
}
}
int ans=inf;
for (int i = 0; i < (1<<m); ++i)
ans=min(ans,dp[i]);
cout<<ans<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |