Submission #837445

# Submission time Handle Problem Language Result Execution time Memory
837445 2023-08-25T10:57:08 Z Liudas Soccer (JOI17_soccer) C++17
100 / 100
385 ms 27116 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
struct node{
	int type;
	int val;
	int x, y;
	bool operator<(const node & a)const{
		return val > a.val;
	}
};
signed main(){
	int X, Y, A, B, C, N;
	cin >> X >> Y >> A >> B >> C >> N;
	vector<pair<int,int>> players(N);
	vector<vector<int>> pos(X + 10, vector<int>(Y + 10, 1e9));
	queue<array<int, 3>> populate;
	for(int i = 0; i < N; i ++){
		cin >> players[i].first >> players[i].second;
		populate.push({players[i].first, players[i].second, 0});
	}
	while(!populate.empty()){
		int x = populate.front()[0], y = populate.front()[1], c = populate.front()[2];
		populate.pop();
		if(pos[x][y] <= c)continue;
		if(x > 0)populate.push({x - 1, y , c+ 1});
		if(y > 0)populate.push({x, y-1, c+1});
		if(x < X)populate.push({x + 1, y, c + 1});
		if(y < Y)populate.push({x, y + 1, c + 1});
		pos[x][y] = c;
	} 
	vector<vector<vector<int>>> arr(X + 5, vector<vector<int>>(Y + 5, vector<int>(3, 1e17)));
	arr[players[0].first][players[0].second][2] = 0;
	priority_queue<node> que;
	que.push({2, 0, players[0].first,players[0].second});
	while(!que.empty()){
		node a = que.top();
		que.pop();
		if(arr[a.x][a.y][a.type] != a.val)continue;
		if(a.type == 2){
			if(a.x > 0 && arr[a.x-1][a.y][2] > a.val + C){que.push({2, a.val+C, a.x-1, a.y});arr[a.x-1][a.y][2] = a.val+C;}
			if(a.y > 0 && arr[a.x][a.y-1][2] > a.val + C){que.push({2, a.val+C, a.x, a.y-1});arr[a.x][a.y-1][2] = a.val+C;}
			if(a.x < X && arr[a.x+1][a.y][2] > a.val + C){que.push({2, a.val+C, a.x+1, a.y});arr[a.x+1][a.y][2] = a.val+C;}
			if(a.y < Y && arr[a.x][a.y+1][2] > a.val + C){que.push({2, a.val+C, a.x, a.y+1});arr[a.x][a.y+1][2] = a.val+C;}

			if(a.val + B < arr[a.x][a.y][0]){que.push({0, a.val+B, a.x, a.y});arr[a.x][a.y][0] = a.val+B;}
			if(a.val + B < arr[a.x][a.y][1]){que.push({1, a.val+B, a.x, a.y});arr[a.x][a.y][1] = a.val+B;}
		}
		if(a.type == 1){
			if(a.y > 0 && arr[a.x][a.y - 1][1] > a.val + A){que.push({1, a.val+A, a.x, a.y - 1});arr[a.x][a.y - 1][1] = a.val+A;}
			if(a.y < Y && arr[a.x][a.y + 1][1] > a.val + A){que.push({1, a.val+A, a.x, a.y + 1});arr[a.x][a.y + 1][1] = a.val+A;}
			if(a.val + pos[a.x][a.y] * C < arr[a.x][a.y][2]){que.push({2, a.val + pos[a.x][a.y] * C, a.x, a.y}); arr[a.x][a.y][2] = a.val + pos[a.x][a.y] * C;}
		}
		if(a.type == 0){
			if(a.x > 0 && arr[a.x - 1][a.y][0] > a.val + A){que.push({0, a.val+A, a.x - 1, a.y});arr[a.x - 1][a.y][0] = a.val+A;}
			if(a.x < X && arr[a.x + 1][a.y][0] > a.val + A){que.push({0, a.val+A, a.x + 1, a.y});arr[a.x + 1][a.y][0] = a.val+A;}
			if(a.val + pos[a.x][a.y] * C < arr[a.x][a.y][2]){que.push({2, a.val + pos[a.x][a.y] * C, a.x, a.y}); arr[a.x][a.y][2] = a.val + pos[a.x][a.y] * C;}
		}
	}
	cout << arr[players.back().first][players.back().second][2] << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 38 ms 6352 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 228 ms 24664 KB Output is correct
4 Correct 235 ms 24636 KB Output is correct
5 Correct 37 ms 6384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 257 ms 24712 KB Output is correct
2 Correct 245 ms 24680 KB Output is correct
3 Correct 165 ms 21544 KB Output is correct
4 Correct 162 ms 24692 KB Output is correct
5 Correct 172 ms 21448 KB Output is correct
6 Correct 160 ms 24640 KB Output is correct
7 Correct 263 ms 24740 KB Output is correct
8 Correct 237 ms 24748 KB Output is correct
9 Correct 250 ms 24740 KB Output is correct
10 Correct 23 ms 5296 KB Output is correct
11 Correct 256 ms 24760 KB Output is correct
12 Correct 255 ms 24648 KB Output is correct
13 Correct 122 ms 21468 KB Output is correct
14 Correct 275 ms 24788 KB Output is correct
15 Correct 255 ms 21516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 6352 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 228 ms 24664 KB Output is correct
4 Correct 235 ms 24636 KB Output is correct
5 Correct 37 ms 6384 KB Output is correct
6 Correct 257 ms 24712 KB Output is correct
7 Correct 245 ms 24680 KB Output is correct
8 Correct 165 ms 21544 KB Output is correct
9 Correct 162 ms 24692 KB Output is correct
10 Correct 172 ms 21448 KB Output is correct
11 Correct 160 ms 24640 KB Output is correct
12 Correct 263 ms 24740 KB Output is correct
13 Correct 237 ms 24748 KB Output is correct
14 Correct 250 ms 24740 KB Output is correct
15 Correct 23 ms 5296 KB Output is correct
16 Correct 256 ms 24760 KB Output is correct
17 Correct 255 ms 24648 KB Output is correct
18 Correct 122 ms 21468 KB Output is correct
19 Correct 275 ms 24788 KB Output is correct
20 Correct 255 ms 21516 KB Output is correct
21 Correct 43 ms 6496 KB Output is correct
22 Correct 263 ms 24596 KB Output is correct
23 Correct 261 ms 19020 KB Output is correct
24 Correct 266 ms 20600 KB Output is correct
25 Correct 264 ms 24704 KB Output is correct
26 Correct 262 ms 24884 KB Output is correct
27 Correct 163 ms 18488 KB Output is correct
28 Correct 174 ms 19216 KB Output is correct
29 Correct 318 ms 23008 KB Output is correct
30 Correct 128 ms 18992 KB Output is correct
31 Correct 327 ms 24724 KB Output is correct
32 Correct 385 ms 27116 KB Output is correct
33 Correct 198 ms 24640 KB Output is correct
34 Correct 329 ms 24704 KB Output is correct
35 Correct 108 ms 18884 KB Output is correct