QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#280394#7785. Three Rectanglesucup-team1069#WA 18ms3640kbC++234.4kb2023-12-09 15:44:222023-12-09 15:44:23

Judging History

你现在查看的是最新测评结果

  • [2023-12-09 15:44:23]
  • 评测
  • 测评结果:WA
  • 用时:18ms
  • 内存:3640kb
  • [2023-12-09 15:44:22]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()

typedef long long ll;

const int N = 1e6 + 2;
const int mod = 1e9 + 7;

inline int add(int a, int b) {
    a += b;
    if (a >= mod) a -= mod;
    return a;
}

inline int sub(int a, int b) {
    a -= b;
    if (a < 0) a += mod;
    return a;
}

inline int mul(int a, int b) {
    return a * 1ll * b % mod;
}

int H, W, h[3], w[3];
int px[3], py[3];
int ans = 0;

void rec(int i) {
    if (i == 3) {
        int mx = -1, mn = H + 1;
        for (int j = 0; j < 3; ++j) if (px[j] == 0) {
                if (py[j] == 0) mx = max(mx, py[j] + h[j]);
                if (py[j] + h[j] == H) mn = min(mn, py[j]);
        }
        if (mn > mx) return;
        mx = -1, mn = H + 1;
        for (int j = 0; j < 3; ++j) if (px[j] + w[j] == W) {
                if (py[j] == 0) mx = max(mx, py[j] + h[j]);
                if (py[j] + h[j] == H) mn = min(mn, py[j]);
        }
        if (mn > mx) return;
        mx = -1, mn = W + 1;
        for (int j = 0; j < 3; ++j) if (py[j] == 0) {
                if (px[j] == 0) mx = max(mx, py[j] + h[j]);
                if (px[j] + w[j] == W) mn = min(mn, py[j]);
        }
        if (mn > mx) return;
        mx = -1, mn = W + 1;
        for (int j = 0; j < 3; ++j) if (py[j] + h[j] == H) {
                if (px[j] == 0) mx = max(mx, px[j] + w[j]);
                if (px[j] + w[j] == W) mn = min(mn, px[j]);
        }
        if (mn > mx) return;
        int now = 1;
        for (int j = 0; j < 3; ++j) if (px[j] == -1) {
            now = mul(now, max((H - h[j] + 1) * 1ll * (W - w[j] + 1) - (4 - 2 * (h[j] == H) - 2 * (w[j] == W)), 0ll));
        }
        ans = add(ans, now);
        return;
    }
    if (h[i] == H && w[i] == W) {
        px[i] = 0, py[i] = 0;
        rec(i + 1);
        px[i] = -1, py[i] = -1;
        rec(i + 1);
    }
    else if (h[i] == H) {
        px[i] = 0, py[i] = 0;
        rec(i + 1);
        px[i] = W - w[i], py[i] = 0;
        rec(i + 1);
        px[i] = -1, py[i] = -1;
        rec(i + 1);
    }
    else if (w[i] == W) {
        px[i] = 0, py[i] = 0;
        rec(i + 1);
        px[i] = 0, py[i] = H - h[i];
        rec(i + 1);
        px[i] = -1, py[i] = -1;
        rec(i + 1);
    }
    else {
        px[i] = 0, py[i] = 0;
        rec(i + 1);
        px[i] = W - w[i], py[i] = 0;
        rec(i + 1);
        px[i] = 0, py[i] = H - h[i];
        rec(i + 1);
        px[i] = W - w[i], py[i] = H - h[i];
        rec(i + 1);
        px[i] = -1, py[i] = -1;
        rec(i + 1);
    }
}

void solve() {
    ans = 0;
    cin >> H >> W;
    int kek = 0, cnt = 1;
    for (int i = 0; i < 3; ++i) {
        cin >> h[i] >> w[i];
        if (h[i] == H && w[i] == W) {
            kek++;
        }
        else {
            cnt = mul(cnt, mul(H - h[i] + 1, W - w[i] + 1));
        }
        px[i] = -1, py[i] = -1;
    }
    if (kek > 0) {
        cout << cnt << '\n';
        return;
    }
    rec(0);
    int hh = 0, ww = 0;
    for (int i = 0; i < 3; ++i) {
        if (h[i] == H) hh++;
        if (w[i] == W) ww++;
    }
    if (hh == 3) {
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (i == j) continue;
                for (int k = 0; k < 3; ++k) {
                    if (k == j || k == i) continue;
                    if (W <= w[i] + w[j]) continue;
                    if (W - w[i] - w[j] > w[k]) continue;
                    ans = add(ans, max(0, min(w[i], W - w[k] - 1)- max((W - w[j] - w[k]), 1) + 1));
                }
            }
        }
    }
    if (ww == 3) {
        for (int i = 0; i < 3; ++i) {
            swap(h[i], w[i]);
        }
        swap(H, W);
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (i == j) continue;
                for (int k = 0; k < 3; ++k) {
                    if (k == j || k == i) continue;
                    if (W <= w[i] + w[j]) continue;
                    if (W - w[i] - w[j] > w[k]) continue;
                    ans = add(ans, max(0, min(w[i], W - w[k] - 1)- max((W - w[j] - w[k]), 1) + 1));
                }
            }
        }
    }
    cout << ans << '\n';
    return;
}

int main() {
    int T;
    cin >> T;
    while (T--) solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

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: 3632kb

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: 1ms
memory: 3580kb

input:

1
1000000000 1000000000
1 1
1 1
1000000000 1000000000

output:

2401

result:

ok 1 number(s): "2401"

Test #4:

score: 0
Accepted
time: 3ms
memory: 3632kb

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: 18ms
memory: 3552kb

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
2
0
0
0
0
0
0
2
4
989330902
0
0
0
0
0
0
0
0
2
0
0
0
0
0
2
0
4
565615002
0
0
0
0
0
0
0
0
2
0
0
0
0
0
2
0
4
141899102
0
0
0
0
0
0
0
0
2
0
0
0
2
2
2
0
4
718183209
0
0
0
0
0
0
0
0
0
0
0
0
2
2
0
2
4
294467309
0
0
0
0
0
0
0
0
0
0
0
2
2
0
2
2
4
87...

result:

wrong answer 27th numbers differ - expected: '0', found: '2'