QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#790173 | #7781. Sheep Eat Wolves | Nanani | WA | 1ms | 3844kb | C++17 | 1.9kb | 2024-11-28 03:35:57 | 2024-11-28 03:35:57 |
Judging History
answer
//by 72
#include<bits/stdc++.h>
#define F(i, a, b) for(int i = a; i <= b; i ++)
#define Fd(i, a, b) for(int i = a; i >= b; i --)
#define pb push_back
#define pii pair<int, int>
#define fi first
#define se second
#define int long long
using namespace std;
const int mod = 998244353;
const int N = 105;
const int inf = 1e18;
typedef array<int, 3> a3;
typedef long long ll;
int x, y, p, q, f[N][N][2], vst[N][N][2];
bool judge(int a, int b) {
if(a < 0 || b < 0) return false;
if(! a || ! b) return true;
return a + q >= b;
}
void sol() {
cin >> x >> y >> p >> q;
F(i, 0, x) F(j, 0, y) F(k, 0, 1) f[i][j][k] = inf;
f[0][0][0] = 0;
queue<a3> q;
q.push({0, 0, 0});
while(q.size()) {
auto [u, v, w] = q.front();
if(vst[u][v][w]) continue;
vst[u][v][w] = 1;
int uu = x - u, vv = y - v;
q.pop();
F(a, 0, x) F(b, 0, y) {
if(a + b > p) continue;
// 这次船上载多少
if(w == 0) {
if(! judge(uu - a, vv - b)) continue;
if(f[u + a][v + b][1] > f[u][v][w] + 1) {
q.push({u + a, v + b, 1});
f[u + a][v + b][1] = f[u][v][w] + 1;
}
} else {
if(! judge(u - a, v - b)) continue;
if(f[u - a][v - b][0] > f[u][v][w] + 1) {
q.push({u - a, v - b, 0});
f[u - a][v - b][0] = f[u][v][w] + 1;
}
}
}
}
int res = inf;
F(i, 0, y) res = min(res, f[x][i][1]);
// cout << f[x][y][1] << "??\n";
if(res == inf) cout << "-1\n";
else cout << (res + 1) / 2 << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
F(i, 1, t) sol();
return 0;
}
//sldl
詳細信息
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3844kb
input:
4 4 3 1
output:
2
result:
wrong answer 1st numbers differ - expected: '3', found: '2'