QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#661502#7781. Sheep Eat Wolvesruoye123456WA 0ms3560kbC++201.8kb2024-10-20 16:34:162024-10-20 16:34:16

Judging History

你现在查看的是最新测评结果

  • [2024-10-20 16:34:16]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3560kb
  • [2024-10-20 16:34:16]
  • 提交

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();
	}
}

详细

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'