QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#755980#7781. Sheep Eat WolvesStar_s#WA 0ms3840kbC++141.1kb2024-11-16 18:36:582024-11-16 18:36:58

Judging History

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

  • [2024-11-16 18:36:58]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3840kb
  • [2024-11-16 18:36:58]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

int sheep, wolf, n, k;
bool vis[105][105][2];

int bfs(int x, int y)
{
	queue<pair<pair<int, int>, int> > q;
	q.push({{x, y}, 0});
	vis[x][y][1] = true;
	while (q.size())
	{
		pair<int, int> now = q.front().first;
		int cnt = q.front().second;
		q.pop();
		for (int i = 0; i <= min(n, now.first); i++)
		{
			for (int j = 0; j + i <= n && j <= now.second; j++)
			{
				int s = now.first - i, w = now.second - j;
				if ((s != 0 && w - s > k) || vis[s][w][0])
					continue;
				vis[s][w][0] = true;
				if (s == 0)
				{
					return cnt + 1;
				}
				for (int ii = 0; ii <= min(n, sheep - s); ii++)
				{
					for (int jj = 0; jj + ii <= n && jj <= wolf - w; jj++)
					{
						int ss = (sheep - s) - ii, ww = (wolf - w) - jj;
						if ((ss != 0 && ww - ss > k) || vis[(sheep - ss)][wolf - ww][1])
							continue;
						vis[ss][ww][1] = true;
						q.push({{(sheep - ss), wolf - ww}, cnt + 2});
					}
				}
			}
		}
	}
	return -1;
}

int main()
{
	cin >> sheep >> wolf >> n >> k;
	cout << bfs(sheep, wolf) << endl;
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3600kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

score: 0
Accepted
time: 0ms
memory: 3512kb

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3548kb

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

score: 0
Accepted
time: 0ms
memory: 3840kb

input:

10 9 1 10

output:

19

result:

ok 1 number(s): "19"

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3604kb

input:

15 20 2 5

output:

-1

result:

wrong answer 1st numbers differ - expected: '27', found: '-1'