QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#698268 | #7781. Sheep Eat Wolves | QFshengxiu | WA | 0ms | 3884kb | C++23 | 2.0kb | 2024-11-01 18:28:14 | 2024-11-01 18:28:19 |
Judging History
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'