QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#661502 | #7781. Sheep Eat Wolves | ruoye123456 | WA | 0ms | 3560kb | C++20 | 1.8kb | 2024-10-20 16:34:16 | 2024-10-20 16:34:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef vector<string> VS;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
vector<int> vx;
inline void divide() {sort(vx.begin(),vx.end());vx.erase(unique(vx.begin(),vx.end()),vx.end());}
//inline int mp(int x) {return upper_bound(vx.begin(),vx.end(),x)-vx.begin();}
inline int log_2(int x) {return 31-__builtin_clz(x);}
inline int popcount(int x) {return __builtin_popcount(x);}
inline int lowbit(int x) {return x&-x;}
inline ll Lsqrt(ll x) { ll L = 1,R = 2e9;while(L + 1 < R){ll M = (L+R)/2;if(M*M <= x) L = M;else R = M;}return L;}
struct node
{
int XL,YL,st,step;
};
const int N = 101;
//
bool vis[N][N][2];
void solve()
{
int x,y,p,q;
cin>>x>>y>>p>>q;
queue<node> qu;
qu.push({x,y,0,0});
vis[x][y][0] = 1;
int ans = -1;
while(qu.size())
{
auto [X,Y,st,step] = qu.front();
qu.pop();
//cout<<X<<' '<<Y<<' '<<st<<' '<<step<<'\n';
if(st == 1 && X == x)
{
ans = step;
break;
}
//带走i只狼,j只羊
for(int i=0;i<=p&&i<=Y;++i)
for(int j=0;j+i<=p&&j<=X;++j)
{
if(X - j && Y - i > X - j + q) break;
//cout<<x-(X-j)<<' '<<y-(Y-i)<<' '<<(st^1)<<'\n';
if(!vis[x-(X-j)][y-(Y-i)][st^1])
{
qu.push({x-(X-j),y-(Y-i),st^1,step+1});
vis[x-(X-j)][y-(Y-i)][st^1] = 1;
}
}
}
cout<<ans<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T = 1;
//cin>>T;
while(T--)
{
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3548kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 3560kb
input:
3 5 2 0
output:
-1
result:
wrong answer 1st numbers differ - expected: '5', found: '-1'