QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#265015#7733. Cool, It’s Yesterday Four Times Moreucup-team1303#WA 1ms5840kbC++143.0kb2023-11-25 16:24:212023-11-25 16:24:21

Judging History

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

  • [2023-11-25 16:24:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5840kb
  • [2023-11-25 16:24:21]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 5; 
int n, m; 
int dx[4] = {-1, 1, 0, 0};
int dy[4] = {0, 0, -1, 1}; 
bool flag[N][N], vis[N][N], can[N][N], tmp[N][N]; 
struct node
{
	int x, y;
};
node operator + (const node &x, const node &y)
{
	return {x.x + y.x, x.y + y.y}; 
}
bool compare(const node &x, const node &y)
{
	return (x.x == y.x) ? x.y < y.y : x.x < y.x; 
}
vector <vector <node> > G; 
bool In(int x, int y)
{
	return (x >= 1 && x <= n && y >= 1 && y <= m); 
}
void dfs(int x, int y, vector <node> &T)
{
	vis[x][y] = 1; 
	T.push_back({x, y}); 
	for(int i = 0; i < 4; i++)
	{
		int wx = x + dx[i], wy = y + dy[i]; 
		if(In(wx, wy) && flag[wx][wy] && !vis[wx][wy])
		{
			dfs(wx, wy, T); 
		}
	}
	return; 
}
void pcan(void)
{
	for(int i = 1; i <= n; i++)
		for(int j = 1; j <= m; j++)
			printf("%d%c", can[i][j] ? 1 : 0, " \n"[j == m]); 
	return; 
}
int main(void)
{
	// freopen("A.in", "r", stdin); 
	// freopen("A.out", "w", stdout);
	int Test; scanf("%d", &Test);
	while(Test--)
	{
		scanf("%d%d", &n, &m); 
		G.clear();
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= m; j++)
			{
				char opt; cin >> opt; 
				flag[i][j] = (opt == '.'); can[i][j] = tmp[i][j] = 0; 
			}
		}
		for(int i = 1; i <= n; i++)
		{
			for(int j = 1; j <= m; j++)
			{
				if(!vis[i][j] && flag[i][j]) 
				{
					vector <node> T; 
					dfs(i, j, T); 
					G.push_back(T); 
				}
			}
		}
		int ans = 0; 
		for(auto &S : G) // 枚举连通块
		{
			sort(S.begin(), S.end(), compare); 
			// printf("LTK : \n"); 
			// for(auto I : S) printf("%d, %d\n", I.x, I.y);
			// printf("\n\n");
			// solve f[0] 
			bool okk = 1; 
			for(int i = 1; i <= n; i++)
			{
				for(int j = 1; j <= m; j++)
				{
					// printf("i = %d, j = %d\n", i, j);
					if(!flag[i][j]) {can[i][j] = 0; continue; }
					if(i == S[0].x && j == S[0].y) {can[i][j] = 1; continue; }
					bool ok = 1; 
					for(auto I : S) 
					{
						int wx = i + (I.x - S[0].x), wy = j + (I.y - S[0].y); 
						// printf("LTK : %d, %d\nwx = %d, wy = %d\n", I.x, I.y, wx, wy); 
						if(!In(wx, wy) || !flag[wx][wy]) {ok = 0; break; }
					}
					can[i][j] = ok; 
					if(can[i][j]) okk = 0; 
				}
			}
			// printf("LTKpcan : %d, %d\n", S[0].x, S[0].y); 
			// pcan(); 
			if(okk) ++ans; 
			//solve f[k]
			for(int k = 1; k < (int)S.size(); k++)
			{
				okk = 1; 
				for(int i = 1; i <= n; i++)
					for(int j = 1; j <= m; j++) tmp[i][j] = can[i][j], can[i][j] = 0; 
				node delta = {S[k - 1].x - S[k].x, S[k - 1].y - S[k].y}; 
				for(int i = 1; i <= n; i++)
				{
					for(int j = 1; j <= m; j++)
					{
						if(!flag[i][j]) {can[i][j] = 0; continue; }
						if(i == S[k].x && j == S[k].y) {can[i][j] = 1; continue; }
						node New = (node){i, j} + delta; 
						can[i][j] = In(New.x, New.y) ? tmp[New.x][New.y] : 0; 
						if(can[i][j]) okk = 0; 
					}
				}
				if(okk) ++ans; 
				// printf("LTKpcan : %d, %d\n", S[k].x, S[k].y); 
				// pcan(); 
			}
		}
		printf("%d\n", ans);
	}
	return 0; 
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 4th lines differ - expected: '2', found: '0'