QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781148#7781. Sheep Eat Wolves4eyebirdRE 1ms10604kbC++172.8kb2024-11-25 14:56:212024-11-25 14:56:26

Judging History

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

  • [2024-11-25 14:56:26]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:10604kb
  • [2024-11-25 14:56:21]
  • 提交

answer

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

#define Buff ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
//#define int long long

bool vis[110][110][110][110][2];

int p, q;
int bfs(ll x0, ll y0)
{
    union I4s
    {
        unsigned short s[8];
        unsigned int sx[2];
        unsigned long long ssx;
    } Ts;
    Ts.s[0] = x0, Ts.s[1] = y0;
    Ts.s[2] = 0, Ts.s[3] = 0;
    Ts.sx[1] = 0;
    queue<unsigned long long> qe;
    qe.push(Ts.ssx);
    vis[x0][y0][0][0][0] = 1;
    while (!qe.empty())
    {
        Ts.ssx = qe.front();
        qe.pop();
        
        int x1 = Ts.s[0], y1 = Ts.s[1];
        int x2 = Ts.s[2], y2 = Ts.s[3];
        int as = Ts.sx[1];
        
        int sp1 = p;
        if (as & 1)
            sp1 = min(x2, sp1);
        else
            sp1 = min(x1, sp1);
        
        for (int i = sp1; i >= 0; i--)
        {
            int sp2 = p - i;
            if (as & 1)
                sp2 = min(y2, sp2);
            else
                sp2 = min(y1, sp2);
            
            for (int j = sp2; j >= 0; j--)
            {
                if (as & 1)
                {
                    if (x2 - i == 0 || x2 - i + q >= y2 - j)
                    {
                        if (!vis[x1 + i][y1 + j][x2 - i][y2 - j][!(as & 1)])
                        {
                            vis[x1 + i][y1 + j][x2 - i][y2 - j][!(as & 1)] = 1;
                            Ts.s[0] = x1 + i, Ts.s[1] = y1 + j;
                            Ts.s[2] = x2 - i, Ts.s[3] = y2 - j;
                            Ts.sx[1] = as + 1;
                            qe.push(Ts.ssx);
                        }
                    }
                }
                else
                {
                    if (x1 - i == 0)
                    {
                        return as + 1;
                    }
                    if (x1 - i == 0 || x1 - i + q >= y1 - j)
                    {
                        if (!vis[x1 - i][y1 - j][x2 + i][y2 + j][!(as & 1)])
                        {
                            vis[x1 - i][y1 - j][x2 + i][y2 + j][!(as & 1)] = 1;
                            Ts.s[0] = x1 - i, Ts.s[1] = y1 - j;
                            Ts.s[2] = x2 + i, Ts.s[3] = y2 + j;
                            Ts.sx[1] = as + 1;
                            qe.push(Ts.ssx);
                        }
                    }
                }
            }
        }
    }
    return -1;
}

void solve()
{
    int x, y;
    cin >> x >> y >> p >> q;
    cout << bfs(x, y);
}

signed main()
{
#ifdef YGYYYGJ
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    Buff;
    int _T_ = 1;
    while (_T_--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5636kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 5612kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 1ms
memory: 5700kb

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5868kb

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 1ms
memory: 5676kb

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

score: 0
Accepted
time: 1ms
memory: 5632kb

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

10 9 1 10

output:

19

result:

ok 1 number(s): "19"

Test #8:

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

input:

15 20 2 5

output:

27

result:

ok 1 number(s): "27"

Test #9:

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

input:

18 40 16 7

output:

5

result:

ok 1 number(s): "5"

Test #10:

score: -100
Runtime Error

input:

60 60 8 1

output:


result: