Submission #20922

# Submission time Handle Problem Language Result Execution time Memory
20922 2017-03-21T09:40:27 Z gs14004 Soccer (JOI17_soccer) C++14
100 / 100
633 ms 23128 KB
#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int n, m;
lint a, b, c;
int dis[505][505];

bool ok(int x, int y){
	return x >= 0 && x <= n && y >= 0 && y <= m;
}

struct node{
	int x, y, typ;
	lint dis;
	bool operator<(const node &c)const{
		return dis > c.dis;
	}
};

priority_queue<node> pq;
lint dist[505][505][5];

void enqueue(int x, int y, int t, lint d){
	if(!ok(x, y)) return;
	if(dist[x][y][t] > d){
		dist[x][y][t] = d;
		pq.push({x, y, t, d});
	}
}

int main(){
	memset(dis, 0x3f, sizeof(dis));
	int t;
	cin >> n >> m >> a >> b >> c >> t;
	queue<pi> que;
	pi st, ed;
	for(int i=0; i<t; i++){
		int x, y;
		scanf("%d %d",&x,&y);
		if(i == 0) st = pi(x, y);
		if(i == t-1) ed = pi(x, y);
		dis[x][y] = 0;
		que.push(pi(x, y));
	}
	while(!que.empty()){
		auto x = que.front();
		que.pop();
		for(int i=0; i<4; i++){
			if(ok(x.first + dx[i], x.second + dy[i]) && dis[x.first + dx[i]][x.second + dy[i]] > 1e9){
				dis[x.first + dx[i]][x.second + dy[i]] = dis[x.first][x.second] + 1;
				que.push(pi(x.first + dx[i], x.second + dy[i]));
			}
		}
	}
	memset(dist, 0x3f, sizeof(dist));
	enqueue(st.first, st.second, 4, 0);
	while(!pq.empty()){
		auto x = pq.top();
		pq.pop();
		if(dist[x.x][x.y][x.typ] != x.dis) continue;
		if(x.typ == 4){
			for(int i=0; i<4; i++){
				enqueue(x.x + dx[i], x.y + dy[i], 4, x.dis + c);
				enqueue(x.x, x.y, i, x.dis + b);
			}
		}
		else{
			enqueue(x.x + dx[x.typ], x.y + dy[x.typ], x.typ, x.dis + a);
			enqueue(x.x, x.y, 4, x.dis + dis[x.x][x.y] * c);
		}
	}
	cout << dist[ed.first][ed.second][4];
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:43:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
                       ^

# Verdict Execution time Memory Grader output
1 Correct 86 ms 15372 KB Output is correct
2 Correct 0 ms 12980 KB Output is correct
3 Correct 413 ms 22280 KB Output is correct
4 Correct 433 ms 22284 KB Output is correct
5 Correct 59 ms 13152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 493 ms 22304 KB Output is correct
2 Correct 456 ms 22324 KB Output is correct
3 Correct 386 ms 22304 KB Output is correct
4 Correct 326 ms 22292 KB Output is correct
5 Correct 356 ms 22324 KB Output is correct
6 Correct 343 ms 22292 KB Output is correct
7 Correct 516 ms 22372 KB Output is correct
8 Correct 453 ms 22336 KB Output is correct
9 Correct 523 ms 22372 KB Output is correct
10 Correct 69 ms 15420 KB Output is correct
11 Correct 503 ms 22380 KB Output is correct
12 Correct 533 ms 22324 KB Output is correct
13 Correct 303 ms 22292 KB Output is correct
14 Correct 509 ms 22376 KB Output is correct
15 Correct 389 ms 22376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 15372 KB Output is correct
2 Correct 0 ms 12980 KB Output is correct
3 Correct 413 ms 22280 KB Output is correct
4 Correct 433 ms 22284 KB Output is correct
5 Correct 59 ms 13152 KB Output is correct
6 Correct 493 ms 22304 KB Output is correct
7 Correct 456 ms 22324 KB Output is correct
8 Correct 386 ms 22304 KB Output is correct
9 Correct 326 ms 22292 KB Output is correct
10 Correct 356 ms 22324 KB Output is correct
11 Correct 343 ms 22292 KB Output is correct
12 Correct 516 ms 22372 KB Output is correct
13 Correct 453 ms 22336 KB Output is correct
14 Correct 523 ms 22372 KB Output is correct
15 Correct 69 ms 15420 KB Output is correct
16 Correct 503 ms 22380 KB Output is correct
17 Correct 533 ms 22324 KB Output is correct
18 Correct 303 ms 22292 KB Output is correct
19 Correct 509 ms 22376 KB Output is correct
20 Correct 389 ms 22376 KB Output is correct
21 Correct 69 ms 13664 KB Output is correct
22 Correct 563 ms 22304 KB Output is correct
23 Correct 543 ms 17720 KB Output is correct
24 Correct 633 ms 17860 KB Output is correct
25 Correct 526 ms 22308 KB Output is correct
26 Correct 519 ms 22468 KB Output is correct
27 Correct 236 ms 14036 KB Output is correct
28 Correct 216 ms 14168 KB Output is correct
29 Correct 443 ms 18540 KB Output is correct
30 Correct 199 ms 13904 KB Output is correct
31 Correct 536 ms 22372 KB Output is correct
32 Correct 626 ms 23128 KB Output is correct
33 Correct 416 ms 22284 KB Output is correct
34 Correct 626 ms 22376 KB Output is correct
35 Correct 179 ms 13904 KB Output is correct