QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#648270#7781. Sheep Eat Wolvesenar#RE 0ms0kbC++201.5kb2024-10-17 18:02:322024-10-17 18:02:32

Judging History

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

  • [2024-10-17 18:02:32]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-17 18:02:32]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

const int INF = 1E9;

struct Node {
    int cnt, sp, wv;
};

void solve() {
    int x, y, p, q;
    std::cin >> x >> y >> p >> q;
    std::queue<Node> pq;
    std::vector vis(2, std::vector(101, std::vector<bool>(101)));
    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 = (a + i == x ? 0 : y - b - x + a + i - q); j <= y - b && j <= p - i; ++j) {
                    if (vis[(c + 1) % 2][a + i][b + j]) continue;
                    pq.push({c + 1, a + i, b + j});
                    vis[(c + 1) % 2][a + i][b + j] = 1;
                }
            }
        } else {
            for (int i = 0; i <= a && i <= p; ++i) {
                for (int j = (a == i ? 0 : b - a + i - q); j <= b && j <= p - i; ++j) {
                    if (vis[(c + 1) % 2][a - i][b - j]) continue;
                    pq.push({c + 1, a - i, b - j});
                    vis[(c + 1) % 2][a - i][b - j] = 1;
                }
            }
        }
    }
    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();
    }
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

4 4 3 1

output:


result: