QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#790171 | #7781. Sheep Eat Wolves | Nanani | WA | 0ms | 3824kb | C++17 | 1.8kb | 2024-11-28 03:33:35 | 2024-11-28 03:33:35 |
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;
}
}
}
}
if(f[x][y][1] == inf) cout << "-1\n";
else cout << (f[x][y][1] + 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
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3608kb
input:
4 4 3 1
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
3 5 2 0
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3824kb
input:
2 5 1 1
output:
-1
result:
ok 1 number(s): "-1"
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3528kb
input:
1 1 1 0
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'