QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#661486 | #7781. Sheep Eat Wolves | ruoye123456 | WA | 0ms | 3868kb | C++20 | 1.8kb | 2024-10-20 16:29:31 | 2024-10-20 16:29:32 |
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 && Y == y)
{
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();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3544kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 3580kb
input:
3 3 1 1
output:
5
result:
wrong answer 1st numbers differ - expected: '7', found: '5'