답안 #91254

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
91254 2018-12-26T17:38:12 Z Dat160601 Soccer (JOI17_soccer) C++17
100 / 100
690 ms 62304 KB
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
typedef pair <int, int> pii;
typedef pair <pair <long long, int> , pii> pli;

int n, m, sz, x[100007], y[100007];
long long A, B, C, ans = 0, dist[507][507][5], init[507][507];
int px[] = {+1, -1, 0, 0};
int py[] = {0, 0, +1, -1};
queue < pair <int, int> > q;
priority_queue < pli, vector <pli>, greater <pli> > pr;

int main(){
	scanf("%d %d", &n, &m);
	n ++, m ++;
	scanf("%lld %lld %lld", &A, &B, &C);
	scanf("%d", &sz);
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			init[i][j] = 1e9;
			for(int k = 0; k < 5; k++){
				dist[i][j][k] = 1e16;
			}
		}
	}
	for(int i = 1; i <= sz; i++){
		scanf("%d %d", &x[i], &y[i]);
		x[i] ++, y[i] ++;
		q.push(mp(x[i], y[i]));
		init[x[i]][y[i]] = 0;
	}
	while(!q.empty()){
		int cx = q.front().fi, cy = q.front().se;
		q.pop();
		for(int dir = 0; dir < 4; dir++){
			int nx = cx + px[dir], ny = cy + py[dir];
			if(nx <= 0 || ny <= 0 || nx > n || ny > m) continue;
			if(init[nx][ny] > init[cx][cy] + 1){
				init[nx][ny] = init[cx][cy] + 1;
				q.push(mp(nx, ny));
			}
		}
	}
	/*for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			cout << init[i][j] << " ";
		}
		cout << endl;
	}*/
	dist[x[1]][y[1]][4] = 0;
	pr.push(mp(mp(0, 4), mp(x[1], y[1])));
	while(!pr.empty()){
		int cx = pr.top().se.fi;
		int cy = pr.top().se.se;
		int type = pr.top().fi.se;
		long long val = pr.top().fi.fi;
		pr.pop();
		if(dist[cx][cy][type] != val) continue;
		if(cx == x[sz] && cy == y[sz]){
			printf("%lld", val);
			return 0;
			//ans = min(ans, val);
		}
		if(type < 4){
			int nx = cx + px[type], ny = cy + py[type];
			if(nx > 0 && nx <= n && ny > 0 && ny <= m && dist[nx][ny][type] > val + A){
				dist[nx][ny][type] = val + A;
				pr.push(mp(mp(dist[nx][ny][type], type), mp(nx, ny)));
			}
			val += C * 1LL * init[cx][cy];
		}
		for(int dir = 0; dir < 4; dir++){
			int nx = cx + px[dir], ny = cy + py[dir];
			if(nx <= 0 || ny <= 0 || nx > n || ny > m) continue;
			if(dist[nx][ny][4] > val + C){
				dist[nx][ny][4] = val + C;
				pr.push(mp(mp(dist[nx][ny][4], 4), mp(nx, ny)));
			}
			if(dist[nx][ny][dir] > val + A + B){
				dist[nx][ny][dir] = val + A + B;
				pr.push(mp(mp(dist[nx][ny][dir], dir), mp(nx, ny)));
			}
		}
	}
	printf("~~This should not happen~~");
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~~
soccer.cpp:20:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld", &A, &B, &C);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &sz);
  ~~~~~^~~~~~~~~~~
soccer.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d", &x[i], &y[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11368 KB Output is correct
2 Correct 2 ms 11368 KB Output is correct
3 Correct 172 ms 37304 KB Output is correct
4 Correct 77 ms 37304 KB Output is correct
5 Correct 65 ms 37304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 37304 KB Output is correct
2 Correct 55 ms 37304 KB Output is correct
3 Correct 223 ms 37304 KB Output is correct
4 Correct 598 ms 37460 KB Output is correct
5 Correct 273 ms 37484 KB Output is correct
6 Correct 323 ms 37484 KB Output is correct
7 Correct 196 ms 37648 KB Output is correct
8 Correct 180 ms 37668 KB Output is correct
9 Correct 44 ms 37668 KB Output is correct
10 Correct 28 ms 37668 KB Output is correct
11 Correct 355 ms 62200 KB Output is correct
12 Correct 372 ms 62304 KB Output is correct
13 Correct 264 ms 62304 KB Output is correct
14 Correct 179 ms 62304 KB Output is correct
15 Correct 31 ms 62304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 11368 KB Output is correct
2 Correct 2 ms 11368 KB Output is correct
3 Correct 172 ms 37304 KB Output is correct
4 Correct 77 ms 37304 KB Output is correct
5 Correct 65 ms 37304 KB Output is correct
6 Correct 66 ms 37304 KB Output is correct
7 Correct 55 ms 37304 KB Output is correct
8 Correct 223 ms 37304 KB Output is correct
9 Correct 598 ms 37460 KB Output is correct
10 Correct 273 ms 37484 KB Output is correct
11 Correct 323 ms 37484 KB Output is correct
12 Correct 196 ms 37648 KB Output is correct
13 Correct 180 ms 37668 KB Output is correct
14 Correct 44 ms 37668 KB Output is correct
15 Correct 28 ms 37668 KB Output is correct
16 Correct 355 ms 62200 KB Output is correct
17 Correct 372 ms 62304 KB Output is correct
18 Correct 264 ms 62304 KB Output is correct
19 Correct 179 ms 62304 KB Output is correct
20 Correct 31 ms 62304 KB Output is correct
21 Correct 34 ms 62304 KB Output is correct
22 Correct 541 ms 62304 KB Output is correct
23 Correct 690 ms 62304 KB Output is correct
24 Correct 426 ms 62304 KB Output is correct
25 Correct 440 ms 62304 KB Output is correct
26 Correct 569 ms 62304 KB Output is correct
27 Correct 167 ms 62304 KB Output is correct
28 Correct 461 ms 62304 KB Output is correct
29 Correct 623 ms 62304 KB Output is correct
30 Correct 303 ms 62304 KB Output is correct
31 Correct 151 ms 62304 KB Output is correct
32 Correct 244 ms 62304 KB Output is correct
33 Correct 356 ms 62304 KB Output is correct
34 Correct 56 ms 62304 KB Output is correct
35 Correct 249 ms 62304 KB Output is correct