QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679036 | #7781. Sheep Eat Wolves | surenjamts# | WA | 1ms | 4852kb | C++17 | 1.6kb | 2024-10-26 16:43:49 | 2024-10-26 16:43:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
int x, y, p, q;
bool check(int i, int j, int k){
// if(i == 3 && j == 3 && k == 1) cout << "entered\n";
if(i < 0 || i > x || j < 0 || j > y) return 0;
if(j > i + q && k == 1 && i > 0) return 0;
if(y - j > x - i + q && k == 0 && i < x) return 0;
// if(i == 3 && j == 3 && k == 1) cout << "correct\n";
return 1;
}
struct node{
int s, w, side;
node(int s, int w, int side) : s(s), w(w), side(side) { }
};
vector<node> adj[105][105][5];
int d[105][105][5];
signed main(){
// x = 3, y = 5, p = 2, q = 0;
cin >> x >> y >> p >> q;
for(int i = 0; i <=x; i++){
for(int j = 0; j <= y; j++){
d[i][j][0] = d[i][j][1] = 1e15;
for(int a = 0; a <= i; a++){
for(int b = 0; b <= j; b++){
if(check(i - a, j - b, 1)) adj[i][j][0].emplace_back(i - a, j - b, 1);
}
}
for(int a = 0; a <= x - i; a++){
for(int b = 0; b <= y - j; b++){
if(check(i + a, j + b, 0)) adj[i][j][1].emplace_back(i + a, j + b, 0);
}
}
}
}
queue<node> q;
d[x][y][0] = 0;
q.push({x, y, 0});
while(!q.empty()){
auto it = q.front(); q.pop();
for(auto next : adj[it.s][it.w][it.side]){
if(d[it.s][it.w][it.side] + 1 < d[next.s][next.w][next.side]){
d[next.s][next.w][next.side] = d[it.s][it.w][it.side] + 1;
q.push(next);
}
}
}
int ans = 1e9;
for(int j = 0; j <= y; j++){
ans = min(ans, d[0][j][1]);
}
if(ans > 1e8) cout << "-1\n";
else cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 4852kb
input:
4 4 3 1
output:
1
result:
wrong answer 1st numbers differ - expected: '3', found: '1'