QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#639700#7785. Three RectanglescpismylifeOwOWA 3ms3624kbC++205.3kb2024-10-13 21:38:582024-10-13 21:38:59

Judging History

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

  • [2024-10-13 21:38:59]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:3624kb
  • [2024-10-13 21:38:58]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;
const int MaxN = 1e6 + 5;

long long h, w;
pair<long long, long long> arr[4];

void Inp()
{
    cin >> h >> w;
    for (int x = 1; x <= 3; x++)
    {
        cin >> arr[x].first >> arr[x].second;
    }
}

vector<int> all = {0, 1, 2, 4, 8, 3, 6, 12, 9};

bool Check(int a, int mask)
{
    if (mask == 0)
    {
        return true;
    }
    if (__builtin_popcount(mask) == 1)
    {
        return arr[a].first < h && arr[a].second < w;
    }
    if (mask == 3 || mask == 12)
    {
        return arr[a].second == w;
    }
    return arr[a].first == h;
}

struct Rect
{
    long long a, b, c, d;

    Rect() = default;

    Rect(long long _a, long long _b, long long _x, long long _y)
    {
        a = _a;
        b = _b;
        c = _x;
        d = _y;
    }
};

long long Cnt(int a, int b, int c)
{
    int kk[3] = {a, b, c};
    int cnt = (a == 0) + (b == 0) + (c == 0);
    if (cnt == 0)
    {
        vector<Rect> rect;
        long long res = 0;
        for (int x = 1; x <= 3; x++)
        {
            if (kk[x - 1] & 1)
            {
                rect.push_back(Rect(1, 1, arr[x].first, arr[x].second));
            }
            else if (kk[x - 1] & 2)
            {
                rect.push_back(Rect(1, w - arr[x].second + 1, arr[x].first, w));
            }
            else if (kk[x - 1] & 4)
            {
                rect.push_back(Rect(h - arr[x].first + 1, w - arr[x].second + 1, h, w));
            }
            else
            {
                rect.push_back(Rect(h - arr[x].first + 1, 1, h, arr[x].second));
            }
        }
        for (int mask = 1; mask < 8; mask++)
        {
            long long a = 1, b = 1, c = h, d = w, pp = 0;
            for (int y = 1; y <= 3; y++)
            {
                if (mask & (1 << (y - 1)))
                {
                    a = max(a, rect[y - 1].a);
                    b = max(b, rect[y - 1].b);
                    c = min(c, rect[y - 1].c);
                    d = min(d, rect[y - 1].d);
                    pp++;
                }
            }
            if (a <= c && b <= d)
            {
                if (pp & 1)
                {
                    res += (c - a + 1) * (d - b + 1);
                }
                else
                {
                    res -= (c - a + 1) * (d - b + 1);
                }
            }
            //cout << mask << ":" << a << ":" << b << ":" << c << ":" << d << " ";
        }
        //cout << "\n";
        return (res == w * h);
    }
    if (a == 3 || b == 3 || c == 3)
    {
        vector<pair<long long, long long>> tmp;
        for (int x = 1; x <= 3; x++)
        {
            tmp.push_back(make_pair(kk[x - 1], x));
        }
        sort(tmp.begin(), tmp.end());
        long long upbound = arr[tmp[1].second].first, dowbound = arr[tmp[2].second].first, mid = h - upbound - dowbound;
        if (mid <= 0)
        {
            return (h - arr[tmp[0].second].first + 1) * (w - arr[tmp[0].second].second + 1) % mod -
                                    4 + 2 * (arr[tmp[0].second].first == h) + 2 * (arr[tmp[0].second].second == w);
        }
        if (mid > arr[tmp[0].second].first || upbound - 1 + dowbound - 1 + mid < arr[tmp[0].second].first)
        {
            return 0;
        }
        return min(arr[tmp[0].second].first - mid + 1, min(upbound, dowbound));
    }
    vector<pair<int, int>> tmp;
    for (int x = 1; x <= 3; x++)
    {
        tmp.push_back(make_pair(kk[x - 1], x));
    }
    sort(tmp.begin(), tmp.end());
    long long upbound = arr[tmp[1].second].second, dowbound = arr[tmp[2].second].second, mid = w - upbound - dowbound;
    //if (a == 0 && b == 6 && c == 9) cout << upbound << " " << dowbound << " " << mid << " ";
    if (mid <= 0)
    {
        return (h - arr[tmp[0].second].first + 1) * (w - arr[tmp[0].second].second + 1) % mod -
                                4 + 2 * (arr[tmp[0].second].first == h) + 2 * (arr[tmp[0].second].second == w);
    }
    if (mid > arr[tmp[0].second].second || upbound - 1 + dowbound - 1 + mid < arr[tmp[0].second].second)
    {
        return 0;
    }
    return min(arr[tmp[0].second].second - mid + 1, min(upbound, dowbound));
}

void Exc()
{
    long long res = 0, cur = 1;
    bool avl = false;
    for (int x = 1; x <= 3; x++)
    {
        avl |= (arr[x].first == h && arr[x].second == w);
        cur = cur * (h - arr[x].first + 1) % mod * (w - arr[x].second + 1) % mod;
    }
    if (avl)
    {
        cout << cur << "\n";
        return;
    }
    for (int x : all)
    {
        for (int y : all)
        {
            for (int z : all)
            {
                if (Check(1, x) && Check(2, y) && Check(3, z) && ((x | y | z) == 15))
                {
                    res = (res + Cnt(x, y, z)) % mod;
                    //cout << x << " " << y << " " << z << " " << Cnt(x, y, z) << "\n";
                }
            }
        }
    }
    cout << res << "\n";
}

int main()
{
    //freopen("A.INP", "r", stdin);
    //freopen("A.OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    cin >> test;
    for (int x = 1; x <= test; x++)
    {
        Inp();
        Exc();
    }
    return 0;
}

详细

Test #1:

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

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

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: 3ms
memory: 3568kb

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
777777755
456790164
0
0
0
0
0
6
222222208
555555533
135802502
0
0
0
0
6
222222208
222222208
333333311
814814847
0
0
0
6
222222208
222222208
222222208
111111089
493827185
0
0
6
222222208
222222208
222222208
222222208
888888874
172839523
0
6
222222208
222222208
222222208
222222208
222222...

result:

wrong answer 8th numbers differ - expected: '777777753', found: '777777755'