QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#692800#7781. Sheep Eat Wolves123456zmy#WA 0ms4028kbC++171.1kb2024-10-31 15:03:472024-10-31 15:03:47

Judging History

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

  • [2024-10-31 15:03:47]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:4028kb
  • [2024-10-31 15:03:47]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int dp[2][101][101];
int vis[2][101][101];
int main()
{
    int X,Y,p,q;
    cin>>X>>Y>>p>>q;
    function<int(int,int,int)>f=[&](int x,int y,int s)
    {
        // cerr<<x<<" "<<y<<" "<<s<<endl;
        if(x==0)return 0;
        if(vis[s][x][y])return dp[s][x][y];
        vis[s][x][y]=1;
        int&ans=dp[s][x][y];
        ans=1e9;
        if(s==0)
        {
            for(int i=0;i<=min(p,x);i++)
            {
                for(int j=0;j<=min(p-i,y);j++)
                {
                    if(x-i&&x-i+q<y-j)continue;
                    ans=min(ans,f(x-i,y-j,1)+1);
                }
            }
        }
        else
        {
            for(int i=0;i<=min(p,X-x);i++)
            {
                for(int j=0;j<=min(p-i,Y-y);j++)
                {
                    if(X-x-i&&X-x-i+q<Y-y-j)continue;
                    ans=min(ans,f(x+i,y+j,0)+1);

                }
            }
        }
        // printf("%d %d %d %d\n",s,x,y,ans);
        return dp[s][x][y]=ans;
    };
    int ans=f(X,Y,0);
    printf("%d\n",ans<1e9?ans:-1);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

3 3 1 1

output:

9

result:

wrong answer 1st numbers differ - expected: '7', found: '9'