QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#707170 | #7781. Sheep Eat Wolves | Arkhell | WA | 1ms | 3736kb | C++14 | 1.4kb | 2024-11-03 14:58:36 | 2024-11-03 14:58:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int x,y,p,q;
int ans=1e9;
int vis[101][101][2];
void dfs(int time,int x1,int y1,int x2,int y2,int pos){
if(time>vis[x1][y1][pos]&&vis[x1][y1][pos]!=0){
return;
}
if(x1==x&&y1==y&&time>0){
return;
}
vis[x1][y1][pos]=time;
if(x1==0&&y1==0){
ans=min(ans,time);
return;
}
//cout<<time<<' '<<x1<<' '<<y1<<' '<<x2<<' '<<y2<<' '<<pos<<'\n';
if(pos==1){
for(int i=0;i<=y2;i++){
for(int j=0;j<=x2;j++){
if(i+j>p){
break;
}
if(y2-i-x2+j>q&&x2-j!=0){
continue;
}
dfs(time,x1+j,y1+i,x2-j,y2-i,0);
}
}
}
else{
for(int i=0;i<=y1;i++){
for(int j=0;j<=x1;j++){
if(i+j>p){
break;
}
if((y1-i-x1+j>q&&x1-j!=0)||i+j==0){
continue;
}
dfs(time+1,x1-j,y1-i,x2+j,y2+i,1);
}
}
}
}
void solve(){
cin>>x>>y>>p>>q;
//memset(vis,-1,sizeof(vis));
dfs(0,x,y,0,0,0);
if(ans==1e9){
cout<<-1<<'\n';
}
else{
cout<<ans;
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3736kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3688kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3616kb
input:
1 1 1 0
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'