QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#803#547721#7781. Sheep Eat Wolvesship2077ship2077Success!2024-09-05 08:34:132024-09-05 08:34:13

Details

Extra Test:

Wrong Answer
time: 0ms
memory: 3820kb

input:

44 5 36 3

output:

-1

result:

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

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#547721#7781. Sheep Eat Wolvesship2077WA 10ms4000kbC++23610b2024-09-05 08:28:192024-09-05 08:34:41

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=105,inf=0x3f3f3f3f;
int n,m,p,q,ans=inf,dp[M][M];
int main(){
    scanf("%d%d%d%d",&n,&m,&p,&q);p=min(p,n+m);
    memset(dp,0x3f,sizeof(dp));dp[n][m]=0;
    for (int i=n;~i;i--)
        for (int j=m;~j;j--){
            if (n!=i&&j<m+i-n-q) break;
            for (int x=max(0,p+i-n);x<=p;x++)
                for (int y=i?max(0,j-i-q):0;y<=p&&y<=j;y++)
                    dp[i][j]=min(dp[i][j],dp[i+p-x][j-y+x]+1);
        }
    for (int i=0;i<=m;i++) ans=min(ans,dp[0][i]);
    printf("%d\n",ans==inf?-1:ans*2-1);
    return 0;
}