QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#648138#7781. Sheep Eat Wolvesenar#TL 246ms96552kbC++201.6kb2024-10-17 17:13:522024-10-17 17:13:52

Judging History

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

  • [2024-10-17 17:13:52]
  • 评测
  • 测评结果:TL
  • 用时:246ms
  • 内存:96552kb
  • [2024-10-17 17:13:52]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

const int INF = 1E9;

struct Node {
    int cnt, sp, wv;
    bool operator < (const Node &u) const {
        return cnt > u.cnt;
    }
};

void solve() {
    int x, y, p, q;
    std::cin >> x >> y >> p >> q;
    std::queue<Node> pq;
    std::vector vis(2, std::vector(200, std::vector<bool>(200)));
    int ans = INF;
    pq.push({0, 0, 0});
    while (!pq.empty()) {
        auto [c, a, b] = pq.front();
        pq.pop();
        vis[c % 2][a][b] = 1;
        if (a == x) {
            ans = std::min(ans, c);
            break;
        }
        if (c % 2 == 0) {
            for (int i = 0; i <= x - a && i <= p; ++i) {
                for (int j = 0; j <= y - b && j <= p - i; ++j) {
                    if (y - b - j > x - a - i + q && a + i != x) continue;
                    if (vis[(c + 1) % 2][a + i][b + j]) continue;
                    pq.push({c + 1, a + i, b + j});
                }
            }
        } else {
            for (int i = 0; i <= a && i <= p; ++i) {
                for (int j = 0; j <= b && j <= p - i; ++j) {
                    if (b - j > a - i + q && a - i != 0) continue;
                    if (vis[(c + 1) % 2][a - i][b - j]) continue;
                    pq.push({c + 1, a - i, b - j});
                }
            }
        }
    }
    if (ans == INF) ans = -1;
    std::cout << ans << "\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: 1ms
memory: 3896kb

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1 1 1 0

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

3 3 1 1

output:

7

result:

ok 1 number(s): "7"

Test #6:

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

input:

3 3 2 1

output:

3

result:

ok 1 number(s): "3"

Test #7:

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

input:

10 9 1 10

output:

19

result:

ok 1 number(s): "19"

Test #8:

score: 0
Accepted
time: 246ms
memory: 96552kb

input:

15 20 2 5

output:

27

result:

ok 1 number(s): "27"

Test #9:

score: 0
Accepted
time: 9ms
memory: 7056kb

input:

18 40 16 7

output:

5

result:

ok 1 number(s): "5"

Test #10:

score: -100
Time Limit Exceeded

input:

60 60 8 1

output:


result: