답안 #335360

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335360 2020-12-12T04:06:26 Z ChrisT Soccer (JOI17_soccer) C++17
100 / 100
989 ms 38340 KB
#include <bits/stdc++.h>
using namespace std;
struct State {
	long long d; int x,y,z;
	bool operator< (const State &o) const {
		return d > o.d;
	}
};
const int MN = 505;
long long dist[MN][MN][5];
int pre[MN][MN], dx[4] = {0,0,1,-1}, dy[4] = {1,-1,0,0};
int main() {
	int n,m,a,b,c,k;
	scanf ("%d %d %d %d %d %d",&n,&m,&a,&b,&c,&k);
	queue<pair<int,int>> q; vector<pair<int,int>> bois(k);
	memset(pre,0x3f,sizeof pre);
	for (auto &[x,y] : bois) {
		scanf ("%d %d",&x,&y);
		pre[x][y] = 0; q.push({x,y});
	}
	while (!q.empty()) {
		auto [x,y] = q.front(); q.pop();
		for (int k = 0; k < 4; k++) {
			int nx = x + dx[k], ny = y + dy[k];
			if (nx >= 1 && nx <= n && 1 <= ny && ny <= m && pre[x][y] + 1 < pre[nx][ny]) {
				pre[nx][ny] = pre[x][y] + 1;
				q.push({nx,ny});
			}
		}
	}
	memset(dist,0x3f,sizeof dist);
	auto [sx,sy] = bois[0];
	dist[sx][sy][0] = 0; 
	priority_queue<State> pq;
	pq.push({0,sx,sy,0});
	while (!pq.empty()) {
		auto [d,x,y,z] = pq.top(); pq.pop();
		if (d > dist[x][y][z]) continue;
		if (!z) {
			for (int k = 0; k < 4; k++) {
				int nx = x + dx[k], ny = y + dy[k];
				if (nx < 0 || nx > n || ny < 0 || ny > m) continue;
				if (d + c < dist[nx][ny][0]) {
					dist[nx][ny][0] = d + c;
					pq.push({d+c,nx,ny,0});
				}
				if (d + a < dist[nx][ny][k+1]) {
					dist[nx][ny][k+1] = d + a;
					pq.push({d+a,nx,ny,k+1});
				}
			}
		} else {
			if (d + b + (long long)a * pre[x][y] < dist[x][y][0]) {
				dist[x][y][0] = d + b + (long long)c * pre[x][y];
				pq.push({dist[x][y][0],x,y,0});
			}
			int nx = x + dx[z-1], ny = y + dy[z-1];
			if (nx >= 0 && nx <= n && ny >= 0 && ny <= m && d + a < dist[nx][ny][z]) {
				dist[nx][ny][z] = d + a;
				pq.push({d+a,nx,ny,z});
			} 
		}
	}
	auto [ex,ey] = bois.back();
	printf ("%lld\n",dist[ex][ey][0]);
	return 0;
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   14 |  scanf ("%d %d %d %d %d %d",&n,&m,&a,&b,&c,&k);
      |  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:18:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   18 |   scanf ("%d %d",&x,&y);
      |   ~~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 14564 KB Output is correct
2 Correct 7 ms 11372 KB Output is correct
3 Correct 461 ms 17632 KB Output is correct
4 Correct 572 ms 23760 KB Output is correct
5 Correct 57 ms 11392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 752 ms 36172 KB Output is correct
2 Correct 752 ms 36172 KB Output is correct
3 Correct 475 ms 23892 KB Output is correct
4 Correct 448 ms 17632 KB Output is correct
5 Correct 504 ms 23964 KB Output is correct
6 Correct 495 ms 23764 KB Output is correct
7 Correct 752 ms 36184 KB Output is correct
8 Correct 601 ms 36332 KB Output is correct
9 Correct 677 ms 36208 KB Output is correct
10 Correct 71 ms 14584 KB Output is correct
11 Correct 767 ms 36336 KB Output is correct
12 Correct 796 ms 36184 KB Output is correct
13 Correct 394 ms 23764 KB Output is correct
14 Correct 738 ms 36208 KB Output is correct
15 Correct 589 ms 36208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 14564 KB Output is correct
2 Correct 7 ms 11372 KB Output is correct
3 Correct 461 ms 17632 KB Output is correct
4 Correct 572 ms 23760 KB Output is correct
5 Correct 57 ms 11392 KB Output is correct
6 Correct 752 ms 36172 KB Output is correct
7 Correct 752 ms 36172 KB Output is correct
8 Correct 475 ms 23892 KB Output is correct
9 Correct 448 ms 17632 KB Output is correct
10 Correct 504 ms 23964 KB Output is correct
11 Correct 495 ms 23764 KB Output is correct
12 Correct 752 ms 36184 KB Output is correct
13 Correct 601 ms 36332 KB Output is correct
14 Correct 677 ms 36208 KB Output is correct
15 Correct 71 ms 14584 KB Output is correct
16 Correct 767 ms 36336 KB Output is correct
17 Correct 796 ms 36184 KB Output is correct
18 Correct 394 ms 23764 KB Output is correct
19 Correct 738 ms 36208 KB Output is correct
20 Correct 589 ms 36208 KB Output is correct
21 Correct 70 ms 12304 KB Output is correct
22 Correct 766 ms 23772 KB Output is correct
23 Correct 825 ms 23784 KB Output is correct
24 Correct 856 ms 23936 KB Output is correct
25 Correct 610 ms 23772 KB Output is correct
26 Correct 571 ms 17932 KB Output is correct
27 Correct 169 ms 13356 KB Output is correct
28 Correct 212 ms 13928 KB Output is correct
29 Correct 428 ms 16740 KB Output is correct
30 Correct 184 ms 13676 KB Output is correct
31 Correct 860 ms 36208 KB Output is correct
32 Correct 943 ms 38340 KB Output is correct
33 Correct 462 ms 23764 KB Output is correct
34 Correct 989 ms 36224 KB Output is correct
35 Correct 177 ms 13676 KB Output is correct