QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#679036#7781. Sheep Eat Wolvessurenjamts#WA 1ms4852kbC++171.6kb2024-10-26 16:43:492024-10-26 16:43:49

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 16:43:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4852kb
  • [2024-10-26 16:43:49]
  • 提交

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'