QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#351654#7733. Cool, It’s Yesterday Four Times Moreoscaryang#WA 1ms5876kbC++201.5kb2024-03-12 10:25:052024-03-12 10:25:05

Judging History

你现在查看的是最新测评结果

  • [2024-03-12 10:25:05]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5876kb
  • [2024-03-12 10:25:05]
  • 提交

answer

#include<bits/stdc++.h>

#define vc vector
#define pb emplace_back
#define pii pair<int, int>
#define mkp make_pair
#define rep(i, a, b) for(int i = (a); i <= (b); ++i)
#define lep(i, a, b) for(int i = (a); i >= (b); --i)

using namespace std;

inline int read() {
	int x = 0, w = 0; char ch = getchar(); while(!isdigit(ch)) w |= (ch == '-'), ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return w ? -x : x; 
}

const int N = 1005;
const int dx[5] = {0, 1, -1, 0, 0}, dy[5] = {0, 0, 0, 1, -1};

int n, m, ans, vis[N][N], b[N][N];
char a[N][N];

inline int ok(int x, int y) { return x > 0 && x <= n && y > 0 && y <= m && a[x][y] == '.'; }

inline void bfs(int sx, int sy) {
	rep(i, 1, n) rep(j, 1, m) b[i][j] = ok(i, j); b[sx][sy] = 0;
	queue<pii> Q; Q.push(mkp(sx, sy)); vis[sx][sy] = 1; 
	int tot = 0, fl = 1;
	while(!Q.empty()) {
		auto [x, y] = Q.front(); Q.pop(); ++tot;
		int dx = x - sx, dy = y - sy;
		rep(i, 1, n) rep(j, 1, m) b[i][j] &= ok(i + dx, j + dy);
		for(int i = 0, nx, ny; i < 4; i++) 
			if(ok(nx = x + ::dx[i], ny = y + ::dy[i]) && !vis[nx][ny])
				vis[nx][ny] = 1, Q.push(mkp(nx, ny));
	}
	rep(i, 1, n) rep(j, 1, m) fl &= (!b[i][j]);
	ans += fl * tot;
}

inline void testcase() {
	n = read(); m = read(); ans = 0;
	rep(i, 1, n) scanf("%s", a[i] + 1);
	
	rep(i, 1, n) rep(j, 1, m) vis[i][j] = 0;
	rep(i, 1, n) rep(j, 1, m) if(!vis[i][j] && ok(i, j)) bfs(i, j);
	
	printf("%d\n", ans);
}

signed main() {
	int t = read(); while(t--) testcase(); 
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5876kb

input:

4
2 5
.OO..
O..O.
1 3
O.O
1 3
.O.
2 3
OOO
OOO

output:

3
1
0
0

result:

ok 4 lines

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 5848kb

input:

200
2 4
OOO.
OO..
2 3
OOO
.O.
3 3
O.O
OOO
OO.
4 1
.
.
O
O
1 2
.O
1 1
.
2 5
.OO..
.O.O.
2 1
O
O
1 1
O
1 3
.OO
5 1
O
O
.
O
.
5 2
O.
..
O.
.O
..
5 3
...
...
.OO
..O
OOO
3 5
..O.O
.O.O.
.OO.O
5 2
.O
OO
O.
O.
..
2 1
O
O
3 5
.O.OO
O...O
..OO.
1 5
.....
5 1
O
.
O
.
.
5 3
OOO
OO.
.OO
OO.
O.O
2 1
O
.
5 2
O.
...

output:

2
0
0
2
1
1
3
0
0
1
0
6
9
4
3
0
3
5
2
0
1
5
4
5
2
0
0
5
3
3
1
4
1
0
6
5
2
3
7
3
0
6
2
2
2
0
4
5
6
0
3
2
3
5
2
1
0
2
3
3
4
2
2
0
7
5
4
6
4
3
2
5
2
1
2
1
4
0
0
2
5
1
4
6
4
1
6
2
2
3
4
4
2
1
0
1
9
3
4
11
0
3
2
1
0
0
4
3
1
0
3
4
3
0
3
6
2
5
1
3
3
4
0
2
11
2
2
4
0
4
4
6
2
1
2
3
0
4
0
9
0
3
2
0
0
8
3
2
1
...

result:

wrong answer 1st lines differ - expected: '3', found: '2'