QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#655131 | #7781. Sheep Eat Wolves | enar | WA | 58ms | 3844kb | C++20 | 1.0kb | 2024-10-19 00:41:45 | 2024-10-19 00:41:55 |
Judging History
answer
#include <bits/stdc++.h>
using i64 = long long;
const int INF = 1E4;
void solve() {
int x, y, p, q;
std::cin >> x >> y >> p >> q;
std::vector dp(2, std::vector(x + 1, std::vector<int>(y + 1, INF)));
dp[0][0][0] = dp[1][x][y] = 0;
int opt = 0;
for(int t = 0; t <= x * 2; ++t, opt ^= 1) {
for(int i = 0; i <= p; ++i) {
for(int j = 0; j <= p - i; ++j) {
for(int a = i; a <= x; ++a) {
for(int b = (a == x ? j : std::max(j, y - x + a - q)); b <= y; ++b) {
dp[opt][a][b] = std::min(dp[opt][a][b], dp[opt ^ 1][x - a + i][y - b + j] + 1);
}
}
}
}
}
i64 sum = 0;
int mn = INF;
for(int i = 0; i <= y; ++i) {
mn = std::min(mn, dp[0][x][i]);
}
std::cout << (mn == INF ? -1 : mn) << '\n';
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int T = 1;
// std::cin >> T;
while(T--) {
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3792kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3516kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
1 1 1 0
output:
1
result:
ok 1 number(s): "1"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3616kb
input:
3 3 1 1
output:
7
result:
ok 1 number(s): "7"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
3 3 2 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
10 9 1 10
output:
19
result:
ok 1 number(s): "19"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3520kb
input:
15 20 2 5
output:
27
result:
ok 1 number(s): "27"
Test #9:
score: 0
Accepted
time: 2ms
memory: 3576kb
input:
18 40 16 7
output:
5
result:
ok 1 number(s): "5"
Test #10:
score: 0
Accepted
time: 13ms
memory: 3768kb
input:
60 60 8 1
output:
27
result:
ok 1 number(s): "27"
Test #11:
score: 0
Accepted
time: 14ms
memory: 3564kb
input:
60 60 8 4
output:
27
result:
ok 1 number(s): "27"
Test #12:
score: 0
Accepted
time: 11ms
memory: 3776kb
input:
60 60 8 8
output:
25
result:
ok 1 number(s): "25"
Test #13:
score: 0
Accepted
time: 38ms
memory: 3844kb
input:
60 60 16 1
output:
13
result:
ok 1 number(s): "13"
Test #14:
score: 0
Accepted
time: 46ms
memory: 3772kb
input:
60 60 16 8
output:
11
result:
ok 1 number(s): "11"
Test #15:
score: 0
Accepted
time: 53ms
memory: 3836kb
input:
60 60 16 16
output:
11
result:
ok 1 number(s): "11"
Test #16:
score: 0
Accepted
time: 58ms
memory: 3560kb
input:
60 60 16 24
output:
9
result:
ok 1 number(s): "9"
Test #17:
score: -100
Wrong Answer
time: 1ms
memory: 3548kb
input:
75 15 1 1
output:
-1
result:
wrong answer 1st numbers differ - expected: '175', found: '-1'