QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#281316 | #7783. Military Maneuver | ucup-team197# | WA | 0ms | 3564kb | C++20 | 1.7kb | 2023-12-10 02:36:08 | 2023-12-10 02:36:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int X = 105;
bool vis[X][X][2];
int dist[X][X][2];
int x, y, p, q;
bool feasible(int a, int b, int s) {
if(a < 0 || a > x || b < 0 || b > y) return false;
if(s == 0) {
return y - b <= x - a + q || x - a == 0;
} else {
return b <= a + q || a == 0;
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
cin >> x >> y >> p >> q;
queue<tuple<int, int, int>> qu;
qu.push({x, y, 0});
vis[x][y][0] = 1;
while(!qu.empty()) {
int a, b, s;
tie(a, b, s) = qu.front();
qu.pop();
for(int m = 0; m <= p; m++) {
for(int n = 0; n <= p; n++) {
if(m+n > p) {
continue;
}
if(s == 0) {
if(feasible(a-m, b-n, 1) && !vis[a-m][b-n][1]) {
qu.push({a-m, b-n, 1});
vis[a-m][b-n][1] = 1;
dist[a-m][b-n][1] = dist[a][b][s] + 1;
}
} else {
if(feasible(a+m, b+n, 0) && !vis[a+m][b+n][0]) {
qu.push({a+m, b+n, 0});
vis[a+m][b+n][0] = 1;
dist[a+m][b+n][0] = dist[a][b][s] + 1;
}
}
}
}
}
int ans = 1e9;
for(int w = 0; w <= y; w++) {
if(vis[0][w][1]) {
ans = min(ans, dist[0][w][1]);
}
}
if(ans < (int) 1e9) {
cout << ans << endl;
} else {
cout << -1 << endl;
}
// cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
input:
0 0 2 2 2 3 1 1 3
output:
1
result:
wrong answer 1st numbers differ - expected: '8.3775804', found: '1.0000000', error = '0.8806338'