Submission #1012388

#TimeUsernameProblemLanguageResultExecution timeMemory
1012388vjudge1Selotejp (COCI20_selotejp)C++17
110 / 110
15 ms488 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...