QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#609974#7733. Cool, It’s Yesterday Four Times MoreLittleYooRE 0ms0kbC++201.9kb2024-10-04 14:37:002024-10-04 14:37:03

Judging History

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

  • [2024-10-04 14:37:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-04 14:37:00]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<pair<int, int>> dir = {
	{1, 0},
	{-1, 0},
	{0, -1},
	{0, 1}
};

bitset<1005> f[1005];
void solve()
{
	memset(f, 0, sizeof(f));
	int n, m;
	cin >> n >> m;
	vector a(n + 2, vector<char>(m + 2, 'O'));
	int tot = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j) {
			cin >> a[i][j];
			tot += a[i][j] == '.';
		}

	auto get = [&](int x, int y) { return (x - 1) * m + y - 1; };

	vector rec(n * m, vector<int>());

	auto bfs = [&](int x, int y)  {
		queue<pair<int, int>> q;
		vector vis(n + 2, vector<int>(m + 2));
		vis[x][y] = 1;
		q.emplace(0, 0);

		while(!q.empty()) {
			auto [dx, dy] = q.front();
			rec[get(dx + 1000, dy + 1000)].emplace_back(get(x, y));
			q.pop();

			for(auto &[ddx, ddy] : dir) {
				int sx = x + dx + ddx, sy = y + dy + ddy;
				if(vis[sx][sy] || a[sx][sy] == 'O')
					continue;
				vis[sx][sy] = 1;
				q.emplace(dx + ddx, dy + ddy);
			}
		}
	};


	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			if(a[i][j] == '.')
				bfs(i, j);

	for(int i = -n + 1000; i <= n + 1000; ++i)
		for(int j = -m + 1000; j <= m + 1000; ++j) 
			if(int cur = get(i, j); !rec[cur].empty()) {
		// cerr << "OK\n";
				bitset<1005> winner;
				for(auto &c : rec[cur])
					winner[c] = 1;

				for(int c = 0; c < n * m; ++c) 
					if(winner[c])
						for(int ii = 1; ii <= n; ++ii)
							for(int jj = 1; jj <= m; ++jj)
								if(a[ii][jj] == '.' && !winner[get(ii, jj)])
									f[c][get(ii, jj)] = 1;

		}


	auto ok = [&](int x, int y) {
		return f[get(x, y)].count() == tot - 1;
	};

	int ans = 0;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			if(a[i][j] == '.')
				ans += ok(i, j);
	cout << ans << '\n';

}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T = 1;
	cin >> T;
	while(T--)
		solve();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

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

output:


result: