QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#768517#7781. Sheep Eat WolvesmobbbTL 1784ms4024kbC++201.2kb2024-11-21 11:44:202024-11-21 11:44:20

Judging History

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

  • [2024-11-21 11:44:20]
  • 评测
  • 测评结果:TL
  • 用时:1784ms
  • 内存:4024kb
  • [2024-11-21 11:44:20]
  • 提交

answer

#include <bits/stdc++.h>

#define ll long long

constexpr int N = 101;

int x, y, p, q, dp[N][N][2];// 0, 1

void dfs(int i, int j, int t){
	for (int u = std::max(0, i - p); u <= i; u++){
		for (int v = std::max(0, j - p); v <= j; v++){
			int change = std::abs(i - u) + std::abs(j - v);
			if (change > p) {
				continue;
			}
			int r = x - u, c = y - v;
			if (u + q < v && u != 0) {
				continue;
			}
			if (dp[r][c][t ^ 1] > dp[i][j][t] + 1){
				dp[r][c][t ^ 1] = dp[i][j][t] + 1;
				dfs(r, c, t ^ 1);
			}
		}
	}
}

int main(){
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	std::cin >> x >> y >> p >> q;
	memset(dp, 127, sizeof(dp));
	dp[x][y][0] = 0;
	dfs(x, y, 0);

	int ans = 1E9;
	for (int i = 0;i <= y; i++){
		ans = std::min(ans, dp[x][i][1]);
	}
	// for (int t = 0; t <= 1; t++){
	// 	for (int i = 0; i <= x; i++){
	// 		for (int j = 0; j <= y; j++){
	// 			std::cout << "( " << i << " , " << j << " , " << t << ") : "; 
	// 			std::cout << dp[i][j][t] << " , ";
	// 			std::cout << "( " << x - i << " , " << y - j << " , " << (t ^ 1) << ")\n"; 	
	// 		}
	// 	}
	// }
	if (ans == 1e9){
		std::cout << "-1\n";
	}else{
		std::cout << ans << '\n';
	}

	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3656kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3744kb

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

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

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

10 9 1 10

output:

19

result:

ok 1 number(s): "19"

Test #8:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

15 20 2 5

output:

27

result:

ok 1 number(s): "27"

Test #9:

score: 0
Accepted
time: 10ms
memory: 3808kb

input:

18 40 16 7

output:

5

result:

ok 1 number(s): "5"

Test #10:

score: 0
Accepted
time: 40ms
memory: 3864kb

input:

60 60 8 1

output:

27

result:

ok 1 number(s): "27"

Test #11:

score: 0
Accepted
time: 79ms
memory: 3760kb

input:

60 60 8 4

output:

27

result:

ok 1 number(s): "27"

Test #12:

score: 0
Accepted
time: 157ms
memory: 3920kb

input:

60 60 8 8

output:

25

result:

ok 1 number(s): "25"

Test #13:

score: 0
Accepted
time: 276ms
memory: 3816kb

input:

60 60 16 1

output:

13

result:

ok 1 number(s): "13"

Test #14:

score: 0
Accepted
time: 703ms
memory: 3932kb

input:

60 60 16 8

output:

11

result:

ok 1 number(s): "11"

Test #15:

score: 0
Accepted
time: 1317ms
memory: 3884kb

input:

60 60 16 16

output:

11

result:

ok 1 number(s): "11"

Test #16:

score: 0
Accepted
time: 1784ms
memory: 4020kb

input:

60 60 16 24

output:

9

result:

ok 1 number(s): "9"

Test #17:

score: 0
Accepted
time: 6ms
memory: 3768kb

input:

75 15 1 1

output:

175

result:

ok 1 number(s): "175"

Test #18:

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

input:

50 100 1 0

output:

-1

result:

ok 1 number(s): "-1"

Test #19:

score: 0
Accepted
time: 1076ms
memory: 4024kb

input:

100 100 10 10

output:

35

result:

ok 1 number(s): "35"

Test #20:

score: 0
Accepted
time: 206ms
memory: 3856kb

input:

100 100 10 1

output:

37

result:

ok 1 number(s): "37"

Test #21:

score: -100
Time Limit Exceeded

input:

100 100 10 20

output:


result: