QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#692439 | #7781. Sheep Eat Wolves | 123456zmy# | WA | 0ms | 4016kb | C++17 | 1.1kb | 2024-10-31 14:30:17 | 2024-10-31 14:31:03 |
Judging History
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,x);j++)
{
if(x-i+p<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+p<Y-y-j)continue;
ans=min(ans,f(x+i,y+j,0)+1);
}
}
}
return dp[s][x][y]=ans;
};
int ans=f(X,Y,0);
printf("%d\n",ans<1e9?ans:-1);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3744kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 4016kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3688kb
input:
3 3 1 1
output:
9
result:
wrong answer 1st numbers differ - expected: '7', found: '9'