QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#673360#6563. Four Squarestudy_to_deathWA 0ms3692kbC++146.1kb2024-10-24 21:55:472024-10-24 21:55:47

Judging History

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

  • [2024-10-24 21:55:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3692kb
  • [2024-10-24 21:55:47]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

int sqr;
struct node
{
    int w, h;
} cube[5];
int p[5];
int flag, w, h;
int num[1005];
int ff[5];

void dfs(int step, int f)
{
    if (flag)
        return;
    ff[step] = f;
    if (step == 4)
    {
        w = h = 0;
        int x = 0, y = 0;
        for (int i = 1; i <= 2; i++)
        {
            if (ff[i])
            {
                x += cube[p[i]].h;
                y += cube[p[i]].w;
            }
            else
            {
                y += cube[p[i]].h;
                x += cube[p[i]].w;
            }
        }
        w = max(w, x);
        h = max(h, y);
        x = y = 0;
        for (int i = 3; i <= 4; i++)
        {
            if (ff[i])
            {
                x += cube[p[i]].h;
                y += cube[p[i]].w;
            }
            else
            {
                y += cube[p[i]].h;
                x += cube[p[i]].w;
            }
        }
        w = max(w, x);
        h = max(h, y);
        if (w * h == sqr)
            flag = 1;
        return;
    }
    dfs(step + 1, 1);
    dfs(step + 1, 0);
}

signed main()
{
    for (int i = 1; i <= 4; i++)
    {
        p[i] = i;
        cin >> cube[i].w >> cube[i].h;
        num[cube[i].w]++;
        num[cube[i].h]++;
        if (cube[i].w == cube[i].h)
            num[cube[i].w]--;
    }
    for (int i = 1; i <= 4; i++)
    {
        sqr += cube[i].w * cube[i].h;
    }
    for (int i = 1; i <= 1000; i++)
    {
        if (num[i] == 4)
        {
            cout << 1 << endl;
            return 0;
        }
    }

    for (int i = 1; i <= 1000; i++)
    {
        if (num[i] == 3)
        {
            int len = 0, x;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].w == i)
                    len += cube[j].h;
                else if (cube[j].h == i)
                    len += cube[j].w;
                else
                    x = j;
            }
            if (cube[x].h == len || cube[x].w == len)
            {
                cout << 1 << endl;
                return 0;
            }
        }
    }

    do
    {
        dfs(1, 0);
        dfs(1, 1);
        if (flag)
            break;
    } while (next_permutation(p + 1, p + 5));

    if (flag)
    {
        cout << 1 << endl;
        return 0;
    }

    for (int i = 1; i < 1001; i++)
    {
        if (num[i] == 2)
        {
            int len = 0, x = 0, y = 0;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].w == i)
                    len += cube[j].h;
                else if (cube[j].h == i)
                    len += cube[j].w;
                else
                {
                    if (!x)
                        x = j;
                    else
                        y = j;
                }
            }
            int len1 = 0;
            if (cube[x].h == cube[y].h)
                len1 = cube[x].w + cube[y].w;
            if (len1 == len || len1 == i)
                flag = 1;
            if (cube[x].h == cube[y].w)
                len1 = cube[x].w + cube[y].h;
            if (len1 == len || len1 == i)
                flag = 1;
            if (cube[x].w == cube[y].w)
                len1 = cube[x].h + cube[y].h;
            if (len1 == len || len1 == i)
                flag = 1;
            if (cube[x].w == cube[y].h)
                len1 = cube[x].h + cube[y].w;
            if (len1 == len || len1 == i)
                flag = 1;
            if (flag)
            {
                cout << 1 << endl;
                return 0;
            }
        }
    }

    for (int i = 1; i <= 1000; i++)
    {
        if (num[i] == 2)
        {
            int x = 0, y = 0, len = 0;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].h == i)
                    len += cube[j].w;
                else if (cube[j].w == i)
                    len += cube[j].h;
                else
                {
                    if (!x)
                        x = j;
                    else
                        y = j;
                }
            }
            if (len == cube[x].h)
            {
                if (i + cube[x].w == cube[y].h || i + cube[x].w == cube[y].w)
                    flag = 1;
            }
            else if (len == cube[x].w)
            {
                if (i + cube[x].h == cube[y].h || i + cube[x].h == cube[y].w)
                    flag = 1;
            }
            if (len == cube[y].h)
            {
                if (i + cube[y].w == cube[x].h || i + cube[y].w == cube[x].w)
                    flag = 1;
            }
            else if (len == cube[y].w)
            {
                if (i + cube[y].h == cube[x].h || i + cube[y].h == cube[x].w)
                    flag = 1;
            }
        }
        else
        {
            int x = 0, len[2] = {0}, mx = 0;
            len[0] = 2 * x;
            for (int j = 1; j <= 4; j++)
            {
                if (cube[j].w == i)
                {
                    if (cube[mx].h < cube[j].h)
                        mx = j;
                }
                else if (cube[j].h == i)
                {
                    if (cube[mx].w < cube[mx].h)
                        mx = j;
                }
                else
                {
                    x = j;
                }
            }
            for (int j = 1; j <= 4; j++)
            {
                if (j == x || j == mx)
                    continue;
                if (cube[j].h == i)
                    len[1] += cube[j].w;
                else if (cube[j].w == i)
                    len[1] += cube[j].h;
            }
            if (len[0] == cube[x].h || len[0] == cube[x].w)
            {
                if (len[1] == cube[mx].h || len[1] == cube[mx].w)
                    flag = 1;
            }
        }
        if (flag)
        {
            cout << 1 << endl;
            return 0;
        }
    }

    cout << 0 << endl;
    return 0;
}

詳細信息

Test #1:

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

input:

1 1
1 1
1 1
1 1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3540kb

input:

3 1
3 3
2 2
3 3

output:

0

result:

ok single line: '0'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

2 8
2 8
2 8
2 8

output:

1

result:

ok single line: '1'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

5 3
5 5
3 3
3 5

output:

1

result:

ok single line: '1'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3616kb

input:

1 2
4 8
16 32
64 128

output:

0

result:

ok single line: '0'

Test #6:

score: -100
Wrong Answer
time: 0ms
memory: 3692kb

input:

4 4
2 1
4 4
2 1

output:

1

result:

wrong answer 1st lines differ - expected: '0', found: '1'