QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290037 | #7785. Three Rectangles | willow# | WA | 4ms | 3908kb | C++14 | 2.2kb | 2023-12-24 10:26:21 | 2023-12-24 10:26:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int Add(int x, int y) {
return (x += y) >= mod ? x - mod : x;
}
int Mul(int x, int y) {
return 1ll * x * y % mod;
}
int T, W, H, w[3], h[3];
int Ways(int a, int b) {
return Mul(H - a + 1, W - b + 1);
}
vector<int> all, no;
int Check() {
all.clear(), no.clear();
for(int i = 0; i < 3; ++ i) {
if(H == h[i]) {
all.push_back(i);
}
else {
no.push_back(i);
}
}
if(!all.size()) {
return -1;
}
if((int)all.size() == 1) {
if(h[no[0]] + h[no[1]] >= H && min(w[no[0]], w[no[1]]) + w[all[0]] >= W) {
if(w[no[0]] == W && w[no[1]] == W) {
return Ways(h[all[0]], w[all[0]]) * 2;
}
return 4;
}
return 0;
}
if((int)all.size() == 2) {
if(w[all[0]] + w[all[1]] >= W) {
return Ways(h[no[0]], w[no[0]]) * 2;
}
return 0;
}
// cerr << "? " << endl;
int ans = 0;
for(int i = 0; i < 3; ++ i) {
for(int j = 0; j < 3; ++ j) {
if(i == j) {
continue;
}
int id = -1;
for(int k = 0; k < 3; ++ k) {
if(i != k && j != k) {
id = k;
break;
}
}
if(max(w[i], w[j]) + w[id] >= W) {
ans = Add(ans, 1);
}
if(w[i] + w[j] >= W) {
ans = Add(ans, max(0, W - w[id] - 1));
// cerr << i << " " << j << " " << ans << endl;
continue;
}
int l = max(2, W - w[j] - w[id] + 1), r = min(W - w[id], w[i] + 1);
if(l <= r) {
ans = Add(ans, r - l + 1);
}
// cerr << i << " " << j << " " << l << " " << r << " " << ans << endl;
}
}
return ans;
}
int main() {
for(scanf("%d", &T); T --; ) {
scanf("%d%d", &H, &W);
for(int i = 0; i < 3; ++ i) {
scanf("%d%d", &h[i], &w[i]);
}
int full = 0;
for(int i = 0; i < 3; ++ i) {
if(H == h[i] && W == w[i]) {
full = 1;
break;
}
}
if(full) {
int ans = 1;
for(int i = 0; i < 3; ++ i) {
ans = Mul(ans, Ways(h[i], w[i]));
}
printf("%d\n", ans);
continue;
}
int ans = Check();
if(ans != -1) {
printf("%d\n", ans);
continue;
}
swap(H, W);
for(int i = 0; i < 3; ++ i) {
swap(h[i], w[i]);
}
ans = Check();
if(ans != -1) {
printf("%d\n", ans);
continue;
}
puts("0");
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3852kb
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: 3716kb
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: 3876kb
input:
1 1000000000 1000000000 1 1 1 1 1000000000 1000000000
output:
2401
result:
ok 1 number(s): "2401"
Test #4:
score: 0
Accepted
time: 1ms
memory: 3904kb
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: 3908kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 413046795 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 989330902 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 565615002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 141899102 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 718183209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 294467309 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 87...
result:
wrong answer 2746th numbers differ - expected: '777777771', found: '1777777778'