QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#661486#7781. Sheep Eat Wolvesruoye123456WA 0ms3868kbC++201.8kb2024-10-20 16:29:312024-10-20 16:29:32

Judging History

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

  • [2024-10-20 16:29:32]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3868kb
  • [2024-10-20 16:29:31]
  • 提交

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

Details

Tip: Click on the bar to expand more detailed information

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'