QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#303567 | #7785. Three Rectangles | PetroTarnavskyi# | WA | 0ms | 3804kb | C++20 | 3.0kb | 2024-01-12 18:52:24 | 2024-01-12 18:52:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int mod = 1e9 + 7;
int add(int a, int b)
{
return a + b < mod ? a + b : a + b - mod;
}
int mult(int a, int b)
{
return (LL)a * b % mod;
}
void solve()
{
int W, H;
cin >> W >> H;
VI w(3), h(3);
int cntw = 0;
int cnth = 0;
FOR (i, 0, 3)
{
cin >> w[i] >> h[i];
cnth += h[i] == H;
cntw += w[i] == W;
}
int res = 1;
FOR (i, 0, 3)
res = mult(res, mult(W - w[i] + 1, H - h[i] + 1));
FOR (i, 0, 3)
{
if (w[i] == W && h[i] == H)
{
cout << res << '\n';
return;
}
}
if (cntw == 3 || cnth == 3)
{
if (cnth != 3)
{
swap(H, W);
FOR (i, 0, 3) swap(w[i], h[i]);
}
if (accumulate(ALL(w), 0) >= W)
{
int ans = 0;
FOR (x, 0, 3)
{
FOR (y, 0, 3)
{
FOR (z, 0, 3)
{
int l = 0, r = W;
if (x == 1) l = max(l, w[0]);
if (x == 2) r = min(r, W - w[0]);
if (y == 1) l = max(l, w[1]);
if (y == 2) r = min(r, W - w[1]);
if (z == 1) l = max(l, w[2]);
if (z == 2) r = min(r, W - w[2]);
if (l == 0 || r == W) continue;
if (r <= l && min({x, y, z}) != 0)
{
ans = add(ans, 1);
continue;
}
VI v = {x, y, z};
FOR (i, 0, 3)
{
if (v[i] != 0)
continue;
if (r <= l)
{
assert(W - 2 - w[i] + 1 >= 0);
ans = add(ans, W - 2 - w[i] + 1);
continue;
}
int L = max(1, r - w[i]);
int R = min(l + 1, W - w[i]);
//cerr << i << ' ' << L << ' ' << R << ' ' << l << ' ' << r << '\n';
ans = add(ans, max(R - L, 0));
}
}
}
}
cout << ans << '\n';
return;
}
}
if (cntw == 2 || cnth == 2)
{
if (cnth != 2)
{
swap(H, W);
FOR (i, 0, 3) swap(w[i], h[i]);
}
int sw = 0;
int j = -1;
FOR (i, 0, 3)
{
if (h[i] == H)
sw += w[i];
else
j = i;
}
if (sw >= W)
{
cout << mult(2, mult(W - w[j] + 1, H - h[j] + 1)) << '\n';
return;
}
}
if (cntw == 1 || cnth == 1)
{
if (cnth != 1)
{
swap(H, W);
FOR (i, 0, 3) swap(w[i], h[i]);
}
int wi = 0;
int mnw = W;
int sh = 0;
FOR (i, 0, 3)
{
if (h[i] == H)
wi = w[i];
else
{
sh += h[i];
mnw = min(mnw, w[i]);
}
}
if (sh >= H && mnw + wi >= W)
cout << 4 << '\n';
else
cout << 0 << '\n';
return;
}
cout << 0 << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout << fixed << setprecision(15);
int t;
cin >> t;
while (t--)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
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: 3592kb
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: 3804kb
input:
1 1000000000 1000000000 1 1 1 1 1000000000 1000000000
output:
2401
result:
ok 1 number(s): "2401"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
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:
wrong answer 314th numbers differ - expected: '555555547', found: '0'