Submission #69471982


Source Code Expand

/* Code By WCM */
/*
Date:
大致思路:
复杂度:
期望得分:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <vector>
#include <queue>
#define popc __builtin_popcount

using namespace std;

inline int read();
void write(int);
void writeln(int);

const int inf = 1e9;
int T, H, W, bs[10], f[10][129];

int main() {

//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> T;
	while(T--) {
		cin >> H >> W;
		vector <string> s(H);
		for(int i = 0; i < H; i++) cin >> s[i];
		memset(bs, 0, sizeof(bs));
		for(int i = 0; i <= H; i++) for(int j = 0; j <= (1 << W); j++) f[i][j] = inf;
		for(int i = 0; i < H; i++) for(int j = 0; j < W; j++) if(s[i][j] == '#') bs[i] |= (1 << j);
		for(int S = 0; S < (1 << W); S++) {
			if((S | bs[0]) != bs[0]) continue;
			f[0][S] = popc(bs[0]) - popc(S);
		}
		for(int i = 1; i < H; i++)
			for(int S = 0; S < (1 << W); S++) {
				if((S | bs[i]) != bs[i]) continue;
				for(int t = 0; t < (1 << W); t++) {
					if(f[i - 1][t] == inf) continue;
					bool fl = 1;
					for(int j = 0; j < W - 1; j++) {
						int p1 = (t >> j) & 1, p2 = (t >> (j + 1)) & 1;
						int c1 = (S >> j) & 1, c2 = (S >> (j + 1)) & 1;
						if(p1 && p2 && c1 && c2) { fl = 0; break; }
					}
					if(!fl) continue;
					f[i][S] = min(f[i][S], f[i - 1][t] + popc(bs[i]) - popc(S));
				}
			} 
		int ans = inf;
		for(int S = 0; S < (1 << W); S++) ans = min(ans, f[H - 1][S]);
		printf("%d\n", ans);
	}
	
//	printf("\nThe time used: ");
//	printf("%.2lfs",(double)clock()/CLOCKS_PER_SEC);

	return 0;

}

inline int read() {
	int res = 0, f = 1;
	char ch = getchar();
	while( !(ch >= '0' && ch <= '9') ) {
		if(ch == '-') f = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		res = (res << 1) + (res << 3) + (ch ^ 48);
		ch = getchar();
	}
	return res * f;
}

void write(int x) {
	static int sta[35];
	int top = 0;
	do {
		sta[top++] = x % 10;
		x /= 10;
	} while(x);
	while(top) putchar(sta[--top] ^ 48);
}

void writeln(int x) {
	write(x);
	putchar('\n');
}

Submission Info

Submission Time
Task D - 2x2 Erasing 2
User WZwangchongming
Language C++ 20 (gcc 12.2)
Score 425
Code Size 2227 Byte
Status AC
Exec Time 49 ms
Memory 3852 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 1
AC × 27
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3744 KiB
hand_00.txt AC 49 ms 3704 KiB
hand_01.txt AC 1 ms 3708 KiB
hand_02.txt AC 4 ms 3704 KiB
hand_03.txt AC 1 ms 3812 KiB
hand_04.txt AC 41 ms 3700 KiB
hand_05.txt AC 1 ms 3652 KiB
random_00.txt AC 1 ms 3812 KiB
random_01.txt AC 2 ms 3708 KiB
random_02.txt AC 3 ms 3748 KiB
random_03.txt AC 2 ms 3848 KiB
random_04.txt AC 2 ms 3660 KiB
random_05.txt AC 3 ms 3816 KiB
random_06.txt AC 9 ms 3668 KiB
random_07.txt AC 9 ms 3700 KiB
random_08.txt AC 8 ms 3708 KiB
random_09.txt AC 9 ms 3852 KiB
random_10.txt AC 5 ms 3660 KiB
random_11.txt AC 19 ms 3828 KiB
random_12.txt AC 21 ms 3788 KiB
random_13.txt AC 19 ms 3668 KiB
random_14.txt AC 21 ms 3852 KiB
random_15.txt AC 5 ms 3680 KiB
random_16.txt AC 20 ms 3700 KiB
random_17.txt AC 21 ms 3680 KiB
random_18.txt AC 20 ms 3768 KiB
random_19.txt AC 19 ms 3804 KiB