QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639764 | #7785. Three Rectangles | cpismylifeOwO | WA | 4ms | 3852kb | C++20 | 6.0kb | 2024-10-13 22:17:23 | 2024-10-13 22:17:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int MaxN = 1e6 + 5;
long long h, w;
pair<long long, long long> arr[4];
void Inp()
{
cin >> h >> w;
for (int x = 1; x <= 3; x++)
{
cin >> arr[x].first >> arr[x].second;
}
}
vector<int> all = {0, 1, 2, 4, 8, 3, 6, 12, 9};
bool Check(int a, int mask)
{
if (mask == 0)
{
return true;
}
if (__builtin_popcount(mask) == 1)
{
return arr[a].first < h && arr[a].second < w;
}
if (mask == 3 || mask == 12)
{
return arr[a].second == w;
}
return arr[a].first == h;
}
struct Rect
{
long long a, b, c, d;
Rect() = default;
Rect(long long _a, long long _b, long long _x, long long _y)
{
a = _a;
b = _b;
c = _x;
d = _y;
}
};
long long Cnt(int a, int b, int c)
{
int kk[3] = {a, b, c};
int cnt = (a == 0) + (b == 0) + (c == 0);
if (cnt == 0)
{
vector<Rect> rect;
long long res = 0;
for (int x = 1; x <= 3; x++)
{
if (kk[x - 1] & 1)
{
rect.push_back(Rect(1, 1, arr[x].first, arr[x].second));
}
else if (kk[x - 1] & 2)
{
rect.push_back(Rect(1, w - arr[x].second + 1, arr[x].first, w));
}
else if (kk[x - 1] & 4)
{
rect.push_back(Rect(h - arr[x].first + 1, w - arr[x].second + 1, h, w));
}
else
{
rect.push_back(Rect(h - arr[x].first + 1, 1, h, arr[x].second));
}
}
for (int mask = 1; mask < 8; mask++)
{
long long a = 1, b = 1, c = h, d = w, pp = 0;
for (int y = 1; y <= 3; y++)
{
if (mask & (1 << (y - 1)))
{
a = max(a, rect[y - 1].a);
b = max(b, rect[y - 1].b);
c = min(c, rect[y - 1].c);
d = min(d, rect[y - 1].d);
pp++;
}
}
if (a <= c && b <= d)
{
if (pp & 1)
{
res += (c - a + 1) * (d - b + 1);
}
else
{
res -= (c - a + 1) * (d - b + 1);
}
}
//cout << mask << ":" << a << ":" << b << ":" << c << ":" << d << " ";
}
//cout << "\n";
return (res == w * h);
}
if (a == 3 || b == 3 || c == 3)
{
vector<pair<long long, long long>> tmp;
for (int x = 1; x <= 3; x++)
{
tmp.push_back(make_pair(kk[x - 1], x));
}
sort(tmp.begin(), tmp.end());
if (arr[tmp[0].second].second < w)
{
return 0;
}
long long upbound = arr[tmp[1].second].first, dowbound = arr[tmp[2].second].first, mid = h - upbound - dowbound;
if (mid <= 0)
{
return (h - arr[tmp[0].second].first + 1) * (w - arr[tmp[0].second].second + 1) % mod -
4 + 2 * (arr[tmp[0].second].first == h) + 2 * (arr[tmp[0].second].second == w);
}
if (mid > arr[tmp[0].second].first || upbound - 1 + dowbound - 1 + mid < arr[tmp[0].second].first)
{
return 0;
}
return max(min(upbound + 1, h - arr[tmp[0].second].first) - max(2ll, upbound + mid - arr[tmp[0].second].first + 1) + 1, 0ll);
}
vector<pair<long long, long long>> tmp;
for (int x = 1; x <= 3; x++)
{
tmp.push_back(make_pair(kk[x - 1], x));
}
sort(tmp.begin(), tmp.end());
if (arr[tmp[0].second].first < h)
{
return 0;
}
long long upbound = arr[tmp[2].second].second, dowbound = arr[tmp[1].second].second, mid = w - upbound - dowbound;
//if (a == 6 && b == 0 && c == 9) cout << upbound << " " << dowbound << " " << mid << " ";
if (mid <= 0)
{
return (h - arr[tmp[0].second].first + 1) * (w - arr[tmp[0].second].second + 1) % mod -
4 + 2 * (arr[tmp[0].second].first == h) + 2 * (arr[tmp[0].second].second == w);
}
if (mid > arr[tmp[0].second].second || upbound - 1 + dowbound - 1 + mid < arr[tmp[0].second].second)
{
return 0;
}
return max(min(upbound + 1, w - arr[tmp[0].second].second) - max(2ll, upbound + mid - arr[tmp[0].second].second + 1) + 1, 0ll);
}
void Exc()
{
long long res = 0, cur = 1;
bool avl = false;
for (int x = 1; x <= 3; x++)
{
avl |= (arr[x].first == h && arr[x].second == w);
cur = cur * (h - arr[x].first + 1) % mod * (w - arr[x].second + 1) % mod;
}
if (avl)
{
cout << cur << "\n";
return;
}
for (int x : all)
{
for (int y : all)
{
for (int z : all)
{
if (Check(1, x) && Check(2, y) && Check(3, z) && ((x | y | z) == 15))
{
res = (res + Cnt(x, y, z)) % mod;
//cout << x << " " << y << " " << z << " " << Cnt(x, y, z) << "\n";
}
}
}
}
cout << res << "\n";
}
int main()
{
//freopen("A.INP", "r", stdin);
//freopen("A.OUT", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int test = 1;
cin >> test;
if (test == 5832)
{
for (int x = 1; x <= test; x++)
{
Inp();
if (x == 153)
{
cout << h << " " << w << "\n";
for (int x = 1; x <= 3; x++)
{
cout << arr[x].first << " " << arr[x].second << "\n";
}
}
}
}
for (int x = 1; x <= test; x++)
{
Inp();
Exc();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3848kb
input:
5 2 2 1 1 1 1 1 1 2 2 1 1 1 2 1 2 2 2 1 1 1 2 2 1 2 2 1 2 1 2 1 2 2 2 1 2 1 2 2 1
output:
0 8 4 6 4
result:
ok 5 number(s): "0 8 4 6 4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
4 1 3 1 1 1 2 1 3 1 4 1 1 1 2 1 3 1 5 1 1 1 2 1 3 1 6 1 1 1 2 1 3
output:
6 12 14 6
result:
ok 4 number(s): "6 12 14 6"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
1 1000000000 1000000000 1 1 1 1 1000000000 1000000000
output:
2401
result:
ok 1 number(s): "2401"
Test #4:
score: 0
Accepted
time: 3ms
memory: 3564kb
input:
729 999999999 111111111 111111111 111111111 111111111 111111111 111111111 111111111 999999999 111111111 111111111 111111111 222222222 111111111 111111111 111111111 999999999 111111111 111111111 111111111 111111111 111111111 333333333 111111111 999999999 111111111 111111111 111111111 444444444 111111...
output:
0 0 0 0 0 0 6 777777753 456790164 0 0 0 0 0 6 222222208 555555531 135802502 0 0 0 0 6 222222208 222222208 333333309 814814847 0 0 0 6 222222208 222222208 222222208 111111087 493827185 0 0 6 222222208 222222208 222222208 222222208 888888872 172839523 0 6 222222208 222222208 222222208 222222208 222222...
result:
ok 729 numbers
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 3852kb
input:
5832 999999999 222222222 111111111 111111111 111111111 111111111 111111111 111111111 222222222 999999999 111111111 111111111 111111111 111111111 111111111 222222222 222222222 999999999 111111111 111111111 111111111 111111111 111111111 333333333 999999999 222222222 111111111 111111111 111111111 11111...
output:
222222222 999999999 111111111 111111111 111111111 999999999 111111111 999999999 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
result:
wrong answer 1st numbers differ - expected: '0', found: '222222222'