Submission #445956

#TimeUsernameProblemLanguageResultExecution timeMemory
445956JasiekstrzSelotejp (COCI20_selotejp)C++17
110 / 110
50 ms4324 KiB
#include<bits/stdc++.h> #define fi first #define se second using namespace std; const int N=1e3,M=10; const int INF=1e9+7; int dp[N+10][(1<<M)+10]; int cons(int msk) { int ans=0; while(msk>0) { ans++; while(msk%2==0) msk/=2; while(msk%2==1) msk/=2; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n,m; cin>>n>>m; dp[0][0]=0; for(int j=1;j<(1<<m);j++) dp[0][j]=INF; for(int i=1;i<=n;i++) { int row=0; for(int j=1;j<=m;j++) { char c; cin>>c; if(c=='#') row^=(1<<(m-j)); } for(int j=0;j<(1<<m);j++) dp[i][j]=dp[i-1][j]; for(int b=0;b<m;b++) { for(int j=0;j<(1<<m);j++) { if(j&(1<<b)) dp[i][j^(1<<b)]=min(dp[i][j^(1<<b)],dp[i][j]); } } for(int b=0;b<m;b++) { for(int j=0;j<(1<<m);j++) { if(j&(1<<b)) dp[i][j]=min(dp[i][j],dp[i][j^(1<<b)]+1); } } for(int j=0;j<(1<<m);j++) { if((j&row)!=j) dp[i][j]=INF; else dp[i][j]+=cons(row^j); } } int ans=INF; for(int j=0;j<(1<<m);j++) ans=min(ans,dp[n][j]); cout<<ans<<"\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...