QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#588559#7733. Cool, It’s Yesterday Four Times MoreargtargWA 1ms3640kbC++202.0kb2024-09-25 13:12:522024-09-25 13:12:53

Judging History

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

  • [2024-09-25 13:12:53]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3640kb
  • [2024-09-25 13:12:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
void solve();
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T; cin >> T;
	while (T--)solve();
	return 0;
}
int oo = 0;
void solve() {
	int n, m;
	cin >> n >> m;
	vector<string>s(n);
	vector<bool>v(n * m);
	auto get = [&](int x, int y)->int {
		return x * m + y;
	};
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		for (int j = 0; j < m; j++) {
			if (s[i][j] == '.')v[get(i, j)] = 0;
			else v[get(i, j)] = 1;
		}
	}
	//return;
	vector<int>vis(n * m);
	vector<vector<int>>flag(n * m, vector<int>(n * m));
	vector<int>dx = { 0,0,-1,1 };
	vector<int>dy = { -1,1,0,0 };
	int ans = 0;
	vector<int>add(n * m + 1);
	int cnt = 0;
	auto fail = [&](int x, int y)->bool {
		if (x < 0 || x >= n || y < 0 || y >= m || v[get(x, y)] == 1 || vis[get(x, y)] == 1)return 1;
		return 0;
	};
	auto dfs = [&](auto dfs, int u, int t) ->int{
		if (flag[u][t])return flag[u][t];
		int i = u / m, j = u % m, x = t / m, y = t % m;
		int ok = -1;
		for (int k = 0; k < 4; k++) {
			int ni = dx[k] + i, nj = dy[k] + j, nx = dx[k] + x, ny = dy[k] + y;
			int nu = get(ni, nj), nt = get(nx, ny);
			if (fail(ni, nj))continue;
			if (fail(nx, ny)) {
				ok = 1;
				continue;
			}
			vis[nu] = 1;
			add[++cnt] = nu;
			//add[++cnt] = nt;
			ok = max(dfs(dfs, nu, nt), ok);
		}
		flag[u][t] = ok;
		return ok;
	};
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			int u = get(i, j);
			if (v[u] == 1)continue;
			int ok = 1;
			for (int x = 0; x < n; x++) {
				for (int y = 0; y < m; y++) {
					int t = get(x, y);
					if (v[t] == 1||u==t)continue;
					vis[u] = 1;
					add[++cnt] = u;
					flag[u][t]=dfs(dfs, u, t);
					ok = min(ok, flag[u][t]);
					for (int i = 1; i <= cnt; i++) {
						vis[add[i]] = 0;
					}
					cnt = 0;
				}
			}
			ans += (ok==1);
			//if (ok == 1)cout << i << ' ' << j << endl;
		}
	}
	cout << ans << endl;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3556kb

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: 1ms
memory: 3640kb

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
2
0
0
1
0
5
7
4
4
0
5
4
2
0
1
6
3
4
2
0
0
4
3
3
1
3
1
0
5
4
2
3
4
3
0
6
2
2
2
0
4
6
3
3
2
2
2
5
2
1
0
3
3
3
3
2
2
0
6
5
3
5
5
3
2
3
2
1
2
1
3
0
0
2
4
1
3
6
6
1
4
2
2
2
4
4
2
1
0
1
7
3
4
11
0
3
2
1
0
0
3
3
1
3
3
7
3
0
3
4
2
5
1
3
3
3
0
2
9
2
2
4
0
3
4
3
2
1
2
3
0
4
0
13
3
3
2
4
0
7
3
3
1
...

result:

wrong answer 7th lines differ - expected: '3', found: '2'