UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#195673#3419. 方格判定Sun_wtup10074ms3208kbC++3.4kb2023-10-18 20:25:292023-10-18 22:30:51

answer

#include <bits/stdc++.h>
//#include <windows.h>
//#include <psapi.h>
//#include <time.h>
using namespace std;
#define debug(x) std::cerr<<#x<<'='<<x<<std::endl
#define int long long
char ch[1005][1005];
bool value[1005][1005];
int n, m;
int a, b;
bool judge (int x, int y) {
//	cout << "+";
	if (ch[x][y] == '.') return 1;
	return 0;
}
bool judge2 (int x, int y) {
//	cout << "-";
	if (ch[x][y] == '#') return 1;
	return 0;
}
bool check2 (int x, int y) {
//	cout << x << " " << y << ' ' << judge2 (x, y - 1) << '\n';
	if (judge2 (x - 1, y) and judge2 (x - 1, y + 1) and judge2 (x, y - 1) and judge2 (x, y + 2)) {
//		cout << x << " " << y << ' ' << judge2 (x, y - 1) << "\n+";
		if (judge2 (x + 1, y - 2) and judge2 (x + 1, y + 3)) {
			if (judge2 (x + 2, y - 2) and judge2 (x + 2, y + 3)) {
				if (judge2 (x + 4, y) and judge2 (x + 4, y + 1) and judge2 (x + 3, y - 1) and judge2 (x + 3, y + 2)) {
//					cout << x << "+" << y << "\n"; 
					return 1;
				}
			}
		}
	}
	return 0;
}
void handle (int x, int y) {
	value[x][y] = 1, value[x][y + 1] = 1;
	value[x + 1][y - 1] = 1, value[x + 1][y] = 1,value[x + 1][y + 1] = 1, value[x + 1][y + 2] = 1;
	value[x + 2][y - 1] = 1, value[x + 2][y] = 1,value[x + 2][y + 1] = 1, value[x + 2][y + 2] = 1;
	value[x + 3][y] = 1, value[x + 3][y + 1] = 1;
}
bool check (int x, int y) {
	if (x == 1 or x == n or y == 1 or y == m) {
		return 0;
	}
	if (judge (x, y) and judge (x, y + 1)) {
		if (judge (x + 1, y - 1) and judge (x + 1, y) and judge (x + 1, y + 1) and judge (x + 1, y + 2)) {
			if (judge (x + 2, y - 1) and judge (x + 2, y) and judge (x + 2, y + 1) and judge (x + 2, y + 2)) {
				if (judge (x + 3, y) and judge (x + 3, y + 1)) {
					if (check2(x, y))
					{
//						cout << x << " " << y << "++\n";
						handle (x, y);
					    return 1;
					}
				}
			}
		}
	}
	return 0;
}
signed main()
{
//  freopen("Untitled-2.in","r",stdin);
//  freopen("Untitled-2.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
//  clock_t start,end;    //定义clock_t变量
//  start = clock();      //开始时间
	cin >> n >> m;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			cin >> ch[i][j];
		}
	}
//  end = clock();   //结束时间
//  cout<<"time = "<<double(end-start)/CLOCKS_PER_SEC<<"s"<<endl;//输出时间
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			if (ch[i][j] == '.' and value[i][j] == 0) {
				if (check (i, j) == 1) {
//					cout << i << " " << j << '\n';
//					cout << check (i, j + 7) << " " << check (i, j - 7) << " " << check (i + 7, j) << " " << check (i - 7, j) << '\n';
//					cout << value[i][j + 7] << "\n";
					if ((!value[i][j + 7] and check (i, j + 7)) or (!value[i][j - 7] and check (i, j - 7)) or (!value[i + 7][j] and check (i + 7, j)) or (!value[i - 7][j] and check (i - 7, j))) {
//						cout << i << " " << j << '\n';
//						if ((!value[i][j + 7] and j + 7 <= ) and !value[i][i - 7] and !value[i + 7][j] and !value[i - 7][j])
//						cout << i << " " << j << "\n---";
						a++;
					}
					else {
//						cout << i << " " << j << "\n+++";
						b++;
					}
				}
			}
		}
	}
//  HANDLE hd = GetCurrentProcess();
//  PROCESS_MEMORY_COUNTERS pmc;
//  GetProcessMemoryInfo(hd, &pmc, sizeof(pmc));
//  printf("%lf", double(pmc.WorkingSetSize) / 1024 / 1024);//单位MiB
	cout << a << " " << b;
//  fclose(stdin);
//  fclose(stdout);
	return 0;
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1276kb

input:

17 17
......##########.
......##########.
......##########.
......####..####.
......###....###.
.......

output:

1 0

result:

ok single line: '1 0'

Test #2:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

17 17
...........###...
...........###...
...........###...
...........###...
....##########...
.......

output:

0 1

result:

ok single line: '0 1'

Test #3:

score: 10
Accepted
time: 0ms
memory: 1264kb

input:

17 17
.................
.................
.................
.................
.##############..
.###...

output:

0 1

result:

ok single line: '0 1'

Test #4:

score: 10
Accepted
time: 0ms
memory: 1328kb

input:

50 50
##########...................##############....###
##########...................##############...

output:

1 11

result:

ok single line: '1 11'

Test #5:

score: 10
Accepted
time: 0ms
memory: 1340kb

input:

50 50
......................###.........................
......................###.....................

output:

5 5

result:

ok single line: '5 5'

Test #6:

score: 10
Accepted
time: 0ms
memory: 1344kb

input:

50 50
......##########..................................
......##########.......####################...

output:

7 2

result:

ok single line: '7 2'

Test #7:

score: 10
Accepted
time: 13ms
memory: 3000kb

input:

1000 1000
##########..##########..##########..##########..##########..##########..##########..######...

output:

4316 0

result:

ok single line: '4316 0'

Test #8:

score: 10
Accepted
time: 20ms
memory: 3208kb

input:

1000 1000
.............................................................................................

output:

539 235

result:

ok single line: '539 235'

Test #9:

score: 10
Accepted
time: 21ms
memory: 2304kb

input:

1000 1000
.............................................................................................

output:

3 7

result:

ok single line: '3 7'

Test #10:

score: 10
Accepted
time: 20ms
memory: 2340kb

input:

1000 1000
.............................................................................................

output:

9 1

result:

ok single line: '9 1'

Extra Test:

score: 0
Extra Test Passed