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 |
---|---|---|---|---|---|---|---|---|---|
#290322 | #7785. Three Rectangles | ucup-team2307# | WA | 8ms | 3832kb | C++20 | 6.3kb | 2023-12-24 20:03:52 | 2023-12-24 20:03:52 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) int(x.size())
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
#define fi first
#define se second
#define pb push_back
const int mod = 1e9 + 7;
const ll inf = 1ll<<30;
ll compute_area(vector<array<ll, 4>> boxes) {
ll ans = 0;
for(int msk = 1; msk < 8; msk++) {
array<ll, 4> box {-inf, inf, -inf, inf};
for(int i = 0; i < 3; i++) {
if(((msk >> i) & 1) == 0) continue;
auto A = boxes[i];
box[0] = max(box[0], A[0]);
box[1] = min(box[1], A[1]);
box[2] = max(box[2], A[2]);
box[3] = min(box[3], A[3]);
}
ll area = max(0ll, box[1] - box[0]) * max(0ll, box[3] - box[2]);
if(__builtin_popcount(msk) % 2 == 0) area *= -1;
ans += area;
// cout << msk << " " << area << endl;
}
return ans;
}
ll solve(int H, int W, vector<array<int, 2>> cards) {
ll eH = 0, eW = 0;
for(auto &[h, w] : cards) {
if(h == H && w == W) {
ll ways = 1;
for(auto &[x, y] : cards) {
(ways *= (H - x + 1)) %= mod;
(ways *= (W - y + 1)) %= mod;
}
return ways;
}
eH += h == H;
eW += w == W;
}
if(eH + eW == 0) return 0;
if(eH >= 2 || eW >= 2) {
if(eW >= 2) {
for(auto &[h, w] : cards) swap(h, w);
swap(H, W);
swap(eH, eW);
}
if(eH == 3) {
ll ways = 0;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) if(i != j) {
int k = i ^ j ^ 3;
if(cards[i][1] + cards[j][1] >= W) {
(ways += (W - cards[k][1] + 1)) %= mod;
} else if(int gap = W - cards[i][1] - cards[j][1]; gap <= cards[k][1]) {
ll cur = cards[k][1] - gap + 1;
cur += mod - max(cards[k][1] - cards[i][1] - gap, 0);
cur += mod - max(cards[k][1] - cards[j][1] - gap, 0);
(ways += cur) %= mod;
}
}
}
for(int p = 0; p < 3; p++) {
int a = 0; a += a == p;
int b = a + 1; b += b==p;
if(cards[p][1] + max(cards[a][1], cards[b][1]) >= W) {
(ways += mod - 2) %= mod;//pss and spp
}
}
return ways;
} else {
ll cover = 0, ways;
for(auto [h, w] : cards) {
if(h == H) cover += w;
else ways = (H - h + 1) * 2ll * (W - w + 1) % mod;
}
return cover < W ? 0 : ways;
}
}
auto get_box = [&](array<int, 2> card, int angle) -> array<ll, 4> {
switch(angle) {
case 0:
return array<ll, 4>{0, card[0], 0, card[1]};
case 1:
return array<ll, 4>{H - card[0], H, 0, card[1]};
case 2:
return array<ll, 4>{0, card[0], W - card[1], W};
case 3:
return array<ll, 4>{H - card[0], H, W - card[1], W};
default:
assert(0);
};
};
auto get_angle = [&](array<ll, 4> box) {
if(box[0] == 0 && box[2] == 0) return 0;
if(box[1] == H && box[2] == 0) return 1;
if(box[0] == 0 && box[3] == W) return 2;
if(box[1] == H && box[3] == W) return 3;
return -1;
};
ll ways = 0;
set<vector<array<ll, 4>>> svb;
for(int a = 0; a < 4; a++) {
for(int b = 0; b < 4; b++) {
for(auto c = 0; c < 4; c++) {
vector<array<ll, 4>> vec {
get_box(cards[0], a),
get_box(cards[1], b),
get_box(cards[2], c)
};
if(get_angle(vec[0]) != a) continue;
if(get_angle(vec[1]) != b) continue;
if(get_angle(vec[2]) != c) continue;
// if(1 || svb.insert(vec).second) {
ll A = compute_area(vec);
// cout << a << " " << b << " " << c << " " << A << endl;
ways += A == H*W;
// }
}
}
}
return ways % mod;
}
int slow(int H, int W, vector<array<int, 2>> cards) {
int ways = 0;
for(int a = 0; a + cards[0][0] <= H; a++) {
for(int b = 0; b + cards[0][1] <= W; b++) {
for(int c = 0; c + cards[1][0] <= H; c++) {
for(int d = 0; d + cards[1][1] <= W; d++) {
for(int e = 0; e + cards[2][0] <= H; e++) {
for(int f = 0; f + cards[2][1] <= W; f++) {
vector<array<ll, 4>> boxes(3);
boxes[0] = array<ll, 4>{a, a+cards[0][0], b, b+cards[0][1]};
boxes[1] = array<ll, 4>{c, c+cards[1][0], d, d+cards[1][1]};
boxes[2] = array<ll, 4>{e, e+cards[2][0], f, f+cards[2][1]};
ll A = compute_area(boxes);
ways += A == H*W;
// if(A == 25) {
// cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << " " << compute_area(boxes) << endl;
// }
}
}
}
}
}
}
return ways;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
// rep(a, 1, 6) rep(b, 1, 6) rep(c, 1, 6) rep(d, 1, 6) rep(e, 1, 6) rep(f, 1, 6) {
// cout << a << " " << b << " " << c << " " << d << " " << e << " " << f << endl;
// vector<array<int, 2>> S{{a, b}, {c,d}, {e,f}};
// assert(solve(5, 5, S) == slow(5, 5, S));
// }
// cout << slow(5, 5, {{1, 1}, {1, 5}, {1, 5}}) << endl;
// cout << compute_area({{0, 1, 0, 1}, {0, 1, 0, 5}, {4, 5, 0, 5}}) << endl;
// return 0;
int T;
cin >> T;
// T = 100000;
while(T--) {
int H, W;
vector<array<int, 2>> cards(3);
cin >> H >> W;
// H = 2, W = 2;
for(auto &[h, w] : cards) cin >> h >> w;
// cards = {{1, 2}, {2, 1}, {1, 1}};
cout << solve(H, W, cards) << '\n';
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3832kb
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: 3568kb
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: 3616kb
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: 3604kb
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: 8ms
memory: 3612kb
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 0 413046795 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 989330902 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 565615002 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 141899102 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 718183209 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 294467309 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 87...
result:
wrong answer 17th numbers differ - expected: '4', found: '0'