QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#370656 | #6746. Merge the Rectangles | L_M_Y | WA | 70ms | 39508kb | C++14 | 2.0kb | 2024-03-29 14:31:31 | 2024-03-29 14:31:32 |
Judging History
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 = 1e3 + 5;
const int MOD = 1e9 + 7;
const double eps = 1e-8;
const double PI = acos(-1.0);
int n, m, a[1510][1510], b[1510][1510], sumr[1510][1510] = { 0 }, sumc[1510][1510] = { 0 };
bool check(int x1, int y1, int x2, int y2)
{
for (int i = y1+1; i < y2; i++)
{
if (sumc[i][x2 - 1] - sumc[i][x1 - 1] != 0)
return false;
}
for (int i = x1+1; i < x2; i++)
{
if (sumr[i][y2 - 1] - sumr[i][y1 - 1] != 0)
{
return false;
}
}
return true;
}
bool dfs(int x1, int y1, int x2, int y2)
{
if (check(x1, y1, x2, y2))
return true;
for (int i = y1 + 1; i < y2; i++)
{
if (sumc[i][x2 - 1] - sumc[i][x1 - 1] == x2 - x1)
{
if (dfs(x1, y1, x2, i) && dfs(x1, i, x2, y2))
return true;
}
}
for (int i = x1 + 1; i < x2; i++)
{
if (sumr[i][y2 - 1] - sumr[i][y1 - 1] == y2 - y1)
{
if (dfs(x1, y1, i, y2) && dfs(i, y1, x2, y2))
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: 0ms
memory: 7720kb
input:
3 4 0000 0111 101 101 110
output:
YES
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 5732kb
input:
3 3 110 011 01 11 10
output:
NO
result:
ok answer is NO
Test #3:
score: 0
Accepted
time: 11ms
memory: 39108kb
input:
1500 1500 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
YES
result:
ok answer is YES
Test #4:
score: 0
Accepted
time: 70ms
memory: 39452kb
input:
1500 1500 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
YES
result:
ok answer is YES
Test #5:
score: 0
Accepted
time: 16ms
memory: 39508kb
input:
1500 1500 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...
output:
YES
result:
ok answer is YES
Test #6:
score: -100
Wrong Answer
time: 11ms
memory: 39080kb
input:
1500 1500 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
NO
result:
wrong answer expected YES, found NO