QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#675202#7785. Three RectanglesNyansRE 0ms0kbC++142.7kb2024-10-25 18:06:522024-10-25 18:06:53

Judging History

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

  • [2024-10-25 18:06:53]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-25 18:06:52]
  • 提交

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;
            }
        }
        assert(ans == 0);
        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: 0
Runtime Error

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:


result: