QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#370659#6746. Merge the RectanglesL_M_YWA 47ms55804kbC++141.8kb2024-03-29 14:36:032024-03-29 14:36:04

Judging History

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

  • [2024-03-29 14:36:04]
  • 评测
  • 测评结果:WA
  • 用时:47ms
  • 内存:55804kb
  • [2024-03-29 14:36:03]
  • 提交

answer

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
#define lowbit(x) ((x)&-(x))
#define inf 99999999
const int N = 2e3 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1.0);
int n, m, a[N][N], b[N][N], sumr[N][N] = { 0 }, sumc[N][N] = { 0 };
bool dfs(int x1, int y1, int x2, int y2)
{
	int sum = 0;
	for (int i = y1 + 1; i < y2; i++)
	{
		if (sumc[i][x2 - 1] - sumc[i][x1 - 1] == x2 - x1)
		{
			return (dfs(x1, y1, x2, i) && dfs(x1, i, x2, y2));
		}
		sum += sumc[i][x2 - 1] - sumc[i][x1 - 1];
	}
	for (int i = x1 + 1; i < x2; i++)
	{
		if (sumr[i][y2 - 1] - sumr[i][y1 - 1] == y2 - y1)
		{
			return (dfs(x1, y1, i, y2) && dfs(i, y1, x2, y2));
		}
		sum += sumr[i][y2 - 1] - sumr[i][y1 - 1];
	}
	if (sum == 0)
		return true;
	return false;
}
void solve()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		a[1][i] = a[n + 1][i] = 1;
	for (int i = 1; i <= n; i++)
		b[1][i] = b[m + 1][i] = 1;
	for (int i = 2; i <= n; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++)
			a[i][j + 1] = s[j] - '0';
	}
	for (int i = 2; i <= m; i++)
	{
		string s;
		cin >> s;
		for (int j = 0; j < s.size(); j++)
			b[j + 2][i - 1] = s[j] - '0';
	}
	for (int i = 1; i <= n + 1; i++)
		for (int j = 1; j <= m; j++)
			sumr[i][j] = sumr[i][j - 1] + a[i][j];
	for (int i = 1; i <= m + 1; i++)
		for (int j = 1; j <= n; j++)
			sumc[i][j] = sumc[i][j - 1] + b[i][j];
	if (dfs(1, 1, n + 1, m + 1))
		cout << "YES\n";
	else
		cout << "NO\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int tt = 1;
	//cin >> tt;
	while (tt--)
	{
		solve();
		cout << "\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 4
0000
0111
101
101
110

output:

YES


result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 1ms
memory: 7728kb

input:

3 3
110
011
01
11
10

output:

NO


result:

ok answer is NO

Test #3:

score: 0
Accepted
time: 12ms
memory: 53780kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES


result:

ok answer is YES

Test #4:

score: 0
Accepted
time: 47ms
memory: 55780kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES


result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 30ms
memory: 55780kb

input:

1500 1500
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

YES


result:

ok answer is YES

Test #6:

score: -100
Wrong Answer
time: 16ms
memory: 55804kb

input:

1500 1500
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

NO


result:

wrong answer expected YES, found NO