QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#698268#7781. Sheep Eat WolvesQFshengxiuWA 0ms3884kbC++232.0kb2024-11-01 18:28:142024-11-01 18:28:19

Judging History

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

  • [2024-11-01 18:28:19]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-11-01 18:28:14]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
using namespace std;
using ll = long long;
using LD = long double;
using PII = pair<int, int>;
const int N = 1e3 + 10;
const int inf = 1e18;
const double eps = 1e-10;
const int mod = 1e9 + 7;
int n, _, m, k, z, p, qx, ans;
bool vis[N][N];
int dis[N][N][2];
bool check(int x, int y, int num)
{
    if (x < 0 || y < 0 || x > n || y > m || dis[x][y][z] != inf)
        return false;
    int lx = n - x, ly = m - num - y;
    return (lx == 0 || lx + qx >= ly);
}
void bfs()
{
    for (int i = 0; i <= n; i++)
    {
        for (int j = 0; j <= m; j++)
        {
            dis[i][j][0] = dis[i][j][1] = inf;
        }
    }
    queue<array<int, 4>> q;
    q.push({0, 0, 0, 0});
    while (!q.empty())
    {
        auto [x, y, z, w] = q.front();
        q.pop();
        if (dis[x][y][z] <= w)
            continue;
        dis[x][y][z] = w;
        // cout << x << ' ' << y << ' ' << z << " " << w << endl;
        for (int i = 0; i <= p; i++)
        {
            for (int j = 0; j <= p - i; j++)
            {
                int nx = i + x, ny = j + y, num = p - i - j;
                if (x == 0 && y == 2 && z == 0 && w == 2)
                {
                    // cout << nx << " " << ny << " " << num << endl;
                    int lx = n - nx, ly = m - num - ny;
                    // cout << lx << " " << ly << endl;
                }
                if (!check(nx, ny, num))
                    continue;

                q.push({nx, ny, 1 - z, w + 1});
            }
        }
    }
    int minn = inf;
    for (int i = 0; i <= m; i++)
    {
        minn = min(minn, dis[n][i][0]);
    }
    if (minn == inf)
        cout << -1 << endl;
    else
        cout << minn + 1 << endl;
}
void solve()
{
    cin >> n >> m >> p >> qx;
    bfs();
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(10);
    _ = 1;
    // cin >> _;
    while (_--)
    {
        solve();
    }
}

詳細信息

Test #1:

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

input:

4 4 3 1

output:

3

result:

ok 1 number(s): "3"

Test #2:

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

input:

3 5 2 0

output:

5

result:

ok 1 number(s): "5"

Test #3:

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

input:

2 5 1 1

output:

-1

result:

ok 1 number(s): "-1"

Test #4:

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

input:

1 1 1 0

output:

3

result:

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