QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#271321#7733. Cool, It’s Yesterday Four Times MoreTeracWA 1ms9716kbC++143.8kb2023-12-02 10:21:302023-12-02 10:21:31

Judging History

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

  • [2023-12-02 10:21:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9716kb
  • [2023-12-02 10:21:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace IO {
	#if ONLINE_JUDGE
	#define getc() (IS == IT && (IT = (IS = ibuf) + fread(ibuf, 1, IL, stdin), IS == IT) ? EOF : *IS++)
	#else
	#define getc() getchar()
	#endif
	const int IL = 1 << 21, OL = 1 << 21;
	int olen = 0;
	char ibuf[IL], *IS = ibuf, *IT = ibuf, obuf[OL];
	inline int read() {
		register char ch = getc(); register int x = 0, f = 1;
		while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
		while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
		return x * f;
	}
	inline double readdb() {
		register char ch = getc(); register double x = 0, f = 1;
		while(!isdigit(ch)) { if(ch == '-') f = -1; ch = getc(); }
		while(isdigit(ch)) x = x * 10 + ch - 48, ch = getc();
		if(ch == '.') {
			register double b = 0.1;
			ch = getc();
			while(isdigit(ch)) x += (ch - 48) * b, b *= 0.1, ch = getc();
		}
		return x * f;
	}
	inline int readstr(char *s) {
		register char ch = getc(); register int len = 0;
		while(ch != '.' && ch != 'O') ch = getc();
		while(ch == '.' || ch == 'O') s[++len] = ch, ch = getc();
		return len;
	}
	inline void flush() { fwrite(obuf, 1, olen, stdout); olen = 0; }
	inline void putc(register char ch) { obuf[olen++] = ch; }
	template<class T>
	inline void write(register T x) {
		if(x < 0) obuf[olen++] = '-', x = -x;
		if(x > 9) write(x / 10);
		obuf[olen++] = x % 10 + 48;
	}
} using namespace IO;
const int N = 1e3 + 10, kx[] = {0, 0, 1, -1}, ky[] = {1, -1, 0, 0};
int T, n, m;
vector<char> ch[N];
char s[N];
namespace ufs {
	int fa[N];
	int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
} using namespace ufs;
vector<int> id[N];
bitset<N> bs[N << 1][N << 1], t;
void MAIN() {
	n = read(), m = read();
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= m; j++)
			bs[n + i][m + j].reset(), bs[n - i][m - j].reset();
	for(int i = 1; i <= n; i++) {
		ch[i].resize(m + 5);
		id[i].resize(m + 5);
		readstr(s);
		for(int j = 1; j <= m; j++)
			ch[i][j] = s[j];
	}
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++)
			id[i][j] = (i - 1) * m + j;
	}
	for(int i = 1; i <= n * m; i++) fa[i] = i; 
	int cnt = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			if(ch[i][j] == 'O') continue;
			cnt++;
			for(int k = 0; k < 4; k++) {
				int dx = i + kx[k], dy = j + ky[k];
				if(dx > 0 && dx <= n && dy > 0 && dy <= m && ch[dx][dy] != 'O') {
					int x = find(id[i][j]), y = find(id[dx][dy]);
					if(x != y) fa[x] = y; 
				}
			}
		}
	for(int i = 0; i <= n + 1; i++)
		for(int j = 0; j <= m + 1; j++) {
			if(!i || i == n + 1 || !j || j == m + 1) {
//				if(i == 2 && j == 6) puts("TT");
				for(int k = 1; k <= n; k++)
					for(int l = 1; l <= m; l++)
						if(ch[k][l] == '.') bs[n + i - k][m + j - l][id[k][l]] = 1;
			}
		}
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			if(ch[i][j] == 'O') continue;
			for(int k = 1; k <= n; k++)	
				for(int l = 1; l <= m; l++) {
					if(ch[k][l] != 'O') continue;
					bs[n + k - i][m + l - j][id[i][j]] = 1;
				}
		}
//	for(int i = -n; i <= n; i++)
//		for(int j = -n; j <= n; j++) {
//			printf("%d %d\n", i, j);
//			int x = 0;
//			while((x = bs[n + i][m + j]._Find_next(x)) <= n * m) {
//				printf("%d %d\n", (x - 1) / m + 1, (x - 1) % m + 1); 
//			}
//			puts("");
//		}
	int ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++) {
			if(ch[i][j] == 'O') continue;
			t.reset();
			for(int i1 = 1; i1 <= n; i1++)
				for(int j1 = 1; j1 <= m; j1++) {
					if(ch[i1][j1] == 'O') continue;
					if(find(id[i][j]) == find(id[i1][j1])) {
						t |= bs[n + i1 - i][m + j1 - j];
					}
				}
			ans += t.count() == cnt - 1;
		}
	printf("%d\n", ans);
}
int main() {
	T = read();
	while(T--) MAIN();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 9716kb

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:

3
0
0
2
1
1
3
0
0
1
0
5
1
2
1
0
0
5
2
0
1
3
2
1
2
0
0
5
1
1
1
4
1
0
5
5
2
3
2
3
0
2
2
2
2
0
2
3
1
1
3
2
3
5
2
1
0
1
3
0
4
2
2
0
5
1
4
2
2
3
2
3
2
1
2
1
4
0
0
2
4
1
1
2
0
1
3
2
2
3
4
3
2
1
0
1
1
1
2
2
0
3
2
1
0
0
4
3
1
2
3
6
3
0
1
5
2
5
1
3
2
4
0
2
6
2
2
2
0
4
4
5
2
1
2
3
0
3
0
0
0
1
2
0
0
5
3
1
1
1
...

result:

wrong answer 12th lines differ - expected: '7', found: '5'