QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#675155#7785. Three RectanglesNyansWA 0ms3624kbC++142.7kb2024-10-25 18:03:072024-10-25 18:03:08

Judging History

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

  • [2024-10-25 18:03:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-10-25 18:03:07]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;
const int mod = 1e9 + 7;

int H, W, h[3], w[3];

i64 calc() {
    std::vector<int> a, b;
    for (int i = 0; i < 3; ++i) {
        if (h[i] == H) {
            a.push_back(i);
        } else {
            b.push_back(i);
        }
    }
    if (a.size() == 0) {
        return -1;
    } else if (a.size() == 1) {
        i64 ans = 0;
        if (h[b[0]] + h[b[1]] >= H && std::min(w[b[0]], w[b[1]]) >= W - w[a[0]]) {
            if (std::min(w[b[0]], w[b[1]]) == W) {
                ans = 2ll * (H - h[a[0]] + 1) * (W - w[a[0]] + 1) % mod;
            } else {
                ans = 4;
            }
        }
        return ans;
    } else if (a.size() == 2) {
        i64 ans = 0;
        if (w[a[0]] + w[a[1]] >= W) {
            ans = 2ll * (H - h[b[0]] + 1) * (W - w[b[0]] + 1) % mod;
        }
        return ans;
    } else {
        i64 ans = 0;
        for (int i = 0; i < 3; ++i) {
            for (int j = 0; j < 3; ++j) {
                if (i == j) {
                    continue;
                }
                int k = 3 - i - j;
                if (std::max(w[i], w[j]) + w[k] >= W) {
                    ans += 1, ans %= mod;
                }
                if (w[i] + w[j] >= W) {
                    ans = (ans + W - w[k] - 1) % mod;
                    // std::cout << ans << "\n";
                    continue;
                }
                int l = std::max(2, W - w[j] - w[k] + 1), r = std::min(W - w[k], w[i] + 1);
                ans = (ans + std::max(0, r - l + 1)) % mod;
            }
        }
        return ans;
    }
}

void solve() {
    std::cin >> H >> W;
    for (int i = 0; i < 3; ++i) {
        std::cin >> h[i] >> w[i];
    }

    bool ok = 0;
    for (int i = 0; i < 3; ++i) {
        if (h[i] == H && w[i] == W) {
            ok = 1;
            break;
        }
    }
    if (ok) {
        i64 ans = 1;
        for (int i = 0; i < 3; ++i) {
            ans = 1ll * ans * (1ll * (H - h[i] + 1) * (W - w[i] + 1) % mod) % mod;
        }
        std::cout << ans << "\n";
        return;
    }

    i64 ansh = calc();
    for (int i = 0; i < 3; ++i) {
        std::swap(h[i], w[i]);
    }
    i64 answ = calc();
    if (answ == -1 && ansh == -1) {
        std::cout << "0\n";
    } else {
        // std::cout << ansh << " " << answ << "\n";
        if (ansh != -1) {
            std::cout << ansh << "\n";
        } else {
            std::cout << answ << "\n";
        }
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int T; std::cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

詳細信息

Test #1:

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

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

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

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

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
0
777777753
456790164
0
0
0
0
0
6
0
0
135802502
0
0
0
0
6
222222208
0
0
814814847
0
0
0
0
0
0
222222208
111111087
493827185
0
0
0
0
222222208
222222208
222222208
888888872
172839523
0
0
0
222222208
222222208
0
222222208
666666650
851851868
0
222222208
222222208
222222208
222222208
0
2222...

result:

wrong answer 7th numbers differ - expected: '6', found: '0'