QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#768838 | #7785. Three Rectangles | SGColin# | WA | 3ms | 4108kb | C++14 | 4.2kb | 2024-11-21 14:46:04 | 2024-11-21 14:46:11 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tii;
typedef vector<int> vi;
inline int rd() {
int x = 0;
bool f = 0;
char c = getchar();
for (; !isdigit(c); c = getchar()) f |= (c == '-');
for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
return f ? -x : x;
}
#define eb emplace_back
#define all(s) (s).begin(), (s).end()
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)
#define per(i, a, b) for (int i = (a); i >= (b); --i)
constexpr int N = 5007;
struct rectan {
int h, w, id;
bool operator < (const rectan &obj) const {return h == obj.h ? (w == obj.w ? id < obj.id : w < obj.w) : (h < obj.h);}
bool operator > (const rectan &obj) const {return obj < (*this);}
bool operator == (const rectan &obj) const {return !((*this) < obj || (*this) > obj);}
bool operator != (const rectan &obj) const {return !(*this == obj);}
bool operator <= (const rectan &obj) const {return !(*this > obj);}
bool operator >= (const rectan &obj) const {return !(*this < obj);}
};
const int mod = 1000000007;
inline void calc() {
rectan R{rd(), rd()};
vector<rectan> r;
int HW = 0, H = 0, W = 0;
rep(i, 1, 3) {
rectan rr{rd(), rd()};
if(rr.h == R.h && rr.w == R.w) HW++;
if(rr.h == R.h) H++;
if(rr.w == R.w) W++;
rr.id = i;
r.push_back(rr);
}
if (HW > 0) {
int ans = 1;
for(auto rr : r) {
int res = 1ll * (R.h - rr.h + 1) * (R.w - rr.w + 1) % mod;
ans = (1ll * ans * res) % mod;
}
printf("%d\n", ans);
return;
}
if (W > 0) {
int ans = 0;
if (W == 3) {
sort(all(r));
do {
if (r[0].h + r[2].h >= R.h) ans = (ans + R.h - 1 - r[1].h) % mod;
else {
int low = max(R.h - r[2].h - r[1].h + 1, 2);
int up = min(R.h - r[1].h, r[0].h + 1);
if (low <= up) ans = (ans + up - low + 1) % mod;
}
}while (next_permutation(all(r)));
sort(all(r));
if (r[0].h + r[2].h >= R.h) ans = (ans + 2) % mod;
if (r[1].h + r[2].h >= R.h) ans = (ans + 4) % mod;
}
else if (W == 2) {
if (r[0].w != R.w) swap(r[0], r[2]);
if (r[1].w != R.w) swap(r[1], r[2]);
if (r[0].h + r[1].h >= R.h) ans = (ans + 2ll * (R.h - r[2].h +1) * (R.w - r[2].w + 1) % mod) % mod;
}
else if (W == 1) {
if (r[1].w == R.w) swap(r[1], r[0]);
if (r[2].w == R.w) swap(r[2], r[0]);
if(r[1].w + r[2].w >= R.w && r[1].h + r[0].h >= R.h && r[2].h + r[0].h >= R.h) ans = (ans + 4) % mod;
}
printf("%d\n", ans);
return;
}
if (H > 0) {
int ans = 0;
if (H == 3) {
sort(all(r));
do {
if (r[0].w + r[2].w >= R.w) ans = (ans + R.w - r[1].w - 1) % mod;
else {
int low = max(R.w - r[2].w - r[1].w + 1, 2);
int up = min(R.w - r[1].w, r[0].w + 1);
if (low <= up) ans = (ans + up - low + 1) % mod;
}
}while (next_permutation(all(r)));
sort(all(r));
if (r[0].w + r[2].w >= R.w) ans = (ans + 2) % mod;
if (r[1].w + r[2].w >= R.w) ans = (ans + 4) % mod;
}
else if (H == 2) {
if (r[0].h != R.h) swap(r[0], r[2]);
if (r[1].h != R.h) swap(r[1], r[2]);
if (r[0].w + r[1].w >= R.w) ans = (ans + 2ll * (R.w - r[2].w +1) * (R.h - r[2].h + 1) % mod) % mod;
}
else if (H == 1) {
if (r[1].h == R.h) swap(r[1], r[0]);
if (r[2].h == R.h) swap(r[2], r[0]);
if(r[1].h + r[2].h >= R.h && r[1].w + r[0].w >= R.w && r[2].w + r[0].w >= R.w) ans = (ans + 4) % mod;
}
printf("%d\n", ans);
return;
}
puts("0");
return;
}
int main() {
// freopen("1.in","r", stdin);
// freopen("2.out","w", stdout);
per(i, rd(), 1) calc();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4032kb
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: 3732kb
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: 4108kb
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: 3800kb
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: 3ms
memory: 3728kb
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: '4'