QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#697227 | #7785. Three Rectangles | 123456zmy | WA | 1ms | 3652kb | C++14 | 2.1kb | 2024-11-01 12:08:24 | 2024-11-01 12:08:25 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
const int mod = 1e9 + 7;
void solve()
{
int H, W;
cin >> H >> W;
vector<int> vh, vw;
int h[3], w[3];
bool flag = 0;
for (int i = 0; i < 3; i++) {
cin >> h[i] >> w[i];
if (h[i] == H)
vh.push_back(i);
if (w[i] == W)
vw.push_back(i);
if (h[i] == H && w[i] == W)
flag = 1;
}
int cnth = vh.size(), cntw = vw.size();
if (cnth < cntw) {
swap(H, W);
swap(h, w);
swap(vh, vw);
swap(cnth, cntw);
}
auto calc = [&](int i) {
return (H - h[i] + 1) * (W - w[i] + 1) % mod;
};
if (flag) {
cout << calc(0) * calc(1) % mod * calc(2) % mod << endl;
return;
}
auto get_id = [&](int x) {
vector<int> v;
for (int i = 0; i < 3; i++)
if (i != x) v.push_back(i);
return make_pair(v[0], v[1]);
};
if (cnth == 0) {
cout << 0 << endl;
}
if (cnth == 1) {
int i = vh[0];
auto [j, k] = get_id(i);
if (w[i] + min(w[j], w[k]) < W || h[j] + h[k] < H)
cout << 0 << endl;
else
cout << 4 << endl;
}
if (cnth == 2) {
int i = vh[0], j = vh[1];
int k = 3 - i - j;
if (w[i] + w[j] >= W)
cout << 2 * calc(k) % mod << endl;
else
cout << 0 << endl;
}
if (cnth == 3) {
if (w[0] + w[1] + w[2] < W) {
cout << 0 << endl;
return;
}
int ans = 0;
set<pair<int, int>> st;
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
if (i == j) continue;
int k = 3 - i - j;
if (w[i] + w[j] < W) {
ans += min(w[k] - (W - w[i] - w[j]) + 1, W - w[k] + 1);
ans %= mod;
if (w[k] >= W - w[i])
st.insert({ min(k, j), max(k, j) });
if (w[k] >= W - w[j])
st.insert({ min(k, i), max(k, i) });
}
else {
ans += W - w[k] + 1;
ans %= mod;
st.insert({ min(k, i), max(k, i) });
st.insert({ min(k, j), max(k, j) });
}
}
}
ans = (ans - 2 * st.size() + mod) % mod;
cout << ans << endl;
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3652kb
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: 3612kb
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: 3520kb
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: 1ms
memory: 3560kb
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 666666652 333333309 814814847 0 0 0 6 222222208 666666652 888888874 111111087 493827185 0 0 6 222222208 666666652 111111089 111111089 888888872 172839523 0 6 222222208 666666652 111111089 111111089 888888...
result:
wrong answer 25th numbers differ - expected: '222222208', found: '666666652'