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 int long long
#define ins insert
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return;
#define all(x) x.begin(),x.end()
#define _ << " " <<
mt19937 rng(time(0));
const int mod = 998244353,
sze = 1e3 +23,
inf = 1e9,
L = 10;
void _0x0(){
int n,m;
cin>>n>>m;
vector<int> last(1<<m,inf),curr(1<<m,0);
last[0]=0;
vector<char> arr[n];
for(int i=0;i<n;i++){
string s;
cin>>s;
for(auto v:s){
arr[i].pb(v);
}
}
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(arr[i][j]=='.'){
curr[mask]=inf;
}
else{
curr[mask]=min(last[mask], last[mask ^ (1<<j)] +1);
}
}
else{
curr[mask]=min(last[mask], last[mask ^ (1<<j)]);
if(arr[i][j]=='#' && (j ==0 || ( arr[i][j-1]=='.' || (mask & (1<<(j-1)))) ) ){
curr[mask]++;
}
}
}
last=curr;
}
}
putr(*min_element( all(last) ));
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int tt = 1;
// cin>>tt;
while(tt--){
_0x0();
}
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... |