Submission #704993

#TimeUsernameProblemLanguageResultExecution timeMemory
7049931075508020060209tcSelotejp (COCI20_selotejp)C++14
70 / 110
1092 ms16596 KiB
#pragma GCC optimize("O3") #include<bits/stdc++.h> using namespace std; //#define int long long #define X first #define Y second int n;int m; string tgr[1010]; int dp[1010][3010]; int gr[1010]; int col[3010]; int sme[3010][3010]; int bts[3010]; signed main(){ cin>>n>>m; for(int i=1;i<=n;i++){ cin>>tgr[i]; } for(int i=1;i<=n;i++){ for(int j=0;j<m;j++){ if(tgr[i][j]=='#'){ gr[i]+=(1<<j); } } } for(int i=0;i<(1<<m);i++){ for(int j=0;j<m;j++){ if( ((i&(1<<j))!=0) ){ col[i]++; if(j>0&&((i&(1<<(j-1)))!=0)){ col[i]--; } bts[i]++; } } } for(int a=0;a<(1<<m);a++){ for(int b=0;b<(1<<m);b++){ for(int j=0;j<m;j++){ if( ((a&(1<<j))!=0)&&((b&(1<<j))!=0) ){ sme[a][b]++; } } } } for(int i=0;i<=n+1;i++){ for(int j=0;j<(1<<m)+10;j++){ dp[i][j]=1e9; } } dp[0][0]=0; for(int i=1;i<=n+1;i++){ for(int mask=0;mask<(1<<m);mask++){ if(((mask|gr[i])!=gr[i])){continue;} for(int mskb=0;mskb<(1<<m);mskb++){ dp[i][mask]=min(dp[i][mask],dp[i-1][mskb]+bts[mask]-sme[mask][mskb]+col[gr[i]^mask]); } } } cout<<dp[n+1][0]<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...