Submission #1012388

# Submission time Handle Problem Language Result Execution time Memory
1012388 2024-07-02T05:24:13 Z vjudge1 Selotejp (COCI20_selotejp) C++17
110 / 110
15 ms 488 KB
#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
1 Correct 0 ms 348 KB Output is correct
2 Correct 12 ms 484 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 6 ms 484 KB Output is correct
5 Correct 13 ms 348 KB Output is correct
6 Correct 13 ms 484 KB Output is correct
7 Correct 13 ms 348 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 12 ms 480 KB Output is correct
10 Correct 14 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 464 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 12 ms 484 KB Output is correct
3 Correct 3 ms 348 KB Output is correct
4 Correct 6 ms 484 KB Output is correct
5 Correct 13 ms 348 KB Output is correct
6 Correct 13 ms 484 KB Output is correct
7 Correct 13 ms 348 KB Output is correct
8 Correct 12 ms 348 KB Output is correct
9 Correct 12 ms 480 KB Output is correct
10 Correct 14 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 0 ms 464 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 4 ms 344 KB Output is correct
21 Correct 7 ms 488 KB Output is correct
22 Correct 12 ms 348 KB Output is correct
23 Correct 13 ms 348 KB Output is correct
24 Correct 13 ms 488 KB Output is correct
25 Correct 14 ms 348 KB Output is correct
26 Correct 14 ms 476 KB Output is correct
27 Correct 14 ms 484 KB Output is correct
28 Correct 15 ms 480 KB Output is correct