Submission #26938

# Submission time Handle Problem Language Result Execution time Memory
26938 2017-07-07T08:28:37 Z kajebiii Soccer (JOI17_soccer) C++14
100 / 100
366 ms 25632 KB
#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, int> pli;
typedef tuple<int, int, int> ti;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_L = 5e2 + 10;

struct ND {
	ll d; pi p; int t;
	ND() {}
	ND(ll dd, pi pp, int tt) : d(dd), p(pp), t(tt) {}
	bool operator<(const ND &o) const{return d > o.d;}
};
int H, W, N; bool Vis[MAX_L][MAX_L][5];
ll A, B, C, Move[MAX_L][MAX_L], Dis[MAX_L][MAX_L][5];
pi St, En;
int main() {
	cin >> H >> W >> A >> B >> C >> N;
	for(int i=0; i<=H; i++) for(int j=0; j<=W; j++) {
		Move[i][j] = LINF;
		for(int k=0; k<5; k++) Dis[i][j][k] = LINF;
	}

	queue<pi> mQ;
	for(int i=0; i<N; i++) {
		int x, y; scanf("%d%d", &x, &y);
		if(i == 0) St = pi(x, y);
		if(i+1 == N) En = pi(x, y);
		mQ.push(pi(x, y));
		Move[x][y] = 0;
	}
	while(!mQ.empty()) {
		int x, y; tie(x, y) = mQ.front(); mQ.pop();
		for(int k=0; k<4; k++) {
			int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
			if(nx < 0 || ny < 0 || nx > H || ny > W) continue;
			if(Move[nx][ny] > Move[x][y] + C) {
				Move[nx][ny] = Move[x][y] + C;
				mQ.push(pi(nx, ny));
			}
		}
	}
	priority_queue<ND> Q;
	Q.push(ND(0ll, St, 4)); Dis[St.one][St.two][4] = 0ll;
	while(!Q.empty()) {
		ND temp = Q.top(); Q.pop();
		ll d = temp.d; int x, y; tie(x, y) = temp.p; int t = temp.t;
		if(Vis[x][y][t]) continue; Vis[x][y][t] = true;
//		printf("%lld %d %d %d [%d %d]\n", d, x, y, t, En.one, En.two);
		if(x == En.one && y == En.two) {
			printf("%lld\n", d);
			return 0;
		}
		if(t == 4) {
			for(int k=0; k<4; k++) {
				int nx = x + "1012"[k] - '1', ny = y + "0121"[k] - '1';
				if(Dis[x][y][k] > d + B) Q.push(ND(Dis[x][y][k] = d+B, pi(x, y), k));
				if(nx < 0 || ny < 0 || nx > H || ny > W) continue;
				if(Dis[nx][ny][4] > d + C) Q.push(ND(Dis[nx][ny][4] = d+C, pi(nx, ny), 4));
			}
		} else {
			int nx = x + "1012"[t] - '1', ny = y + "0121"[t] - '1';
			if(!(nx < 0 || ny < 0 || nx > H || ny > W))
				if(Dis[nx][ny][t] > d + A) Q.push(ND(Dis[nx][ny][t] = d+A, pi(nx, ny), t));
			if(Dis[x][y][4] > d + Move[x][y]) Q.push(ND(Dis[x][y][4] = d + Move[x][y], pi(x, y), 4));
		}
	}
	return 0;
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:37:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int x, y; scanf("%d%d", &x, &y);
                                  ^
# Verdict Execution time Memory Grader output
1 Correct 23 ms 17872 KB Output is correct
2 Correct 0 ms 15484 KB Output is correct
3 Correct 86 ms 24784 KB Output is correct
4 Correct 36 ms 20180 KB Output is correct
5 Correct 36 ms 15656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 20200 KB Output is correct
2 Correct 33 ms 17916 KB Output is correct
3 Correct 129 ms 24808 KB Output is correct
4 Correct 286 ms 24796 KB Output is correct
5 Correct 153 ms 24828 KB Output is correct
6 Correct 176 ms 24796 KB Output is correct
7 Correct 103 ms 24876 KB Output is correct
8 Correct 123 ms 24840 KB Output is correct
9 Correct 23 ms 16812 KB Output is correct
10 Correct 19 ms 17924 KB Output is correct
11 Correct 249 ms 24884 KB Output is correct
12 Correct 229 ms 24828 KB Output is correct
13 Correct 139 ms 24796 KB Output is correct
14 Correct 86 ms 24880 KB Output is correct
15 Correct 13 ms 16240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 17872 KB Output is correct
2 Correct 0 ms 15484 KB Output is correct
3 Correct 86 ms 24784 KB Output is correct
4 Correct 36 ms 20180 KB Output is correct
5 Correct 36 ms 15656 KB Output is correct
6 Correct 36 ms 20200 KB Output is correct
7 Correct 33 ms 17916 KB Output is correct
8 Correct 129 ms 24808 KB Output is correct
9 Correct 286 ms 24796 KB Output is correct
10 Correct 153 ms 24828 KB Output is correct
11 Correct 176 ms 24796 KB Output is correct
12 Correct 103 ms 24876 KB Output is correct
13 Correct 123 ms 24840 KB Output is correct
14 Correct 23 ms 16812 KB Output is correct
15 Correct 19 ms 17924 KB Output is correct
16 Correct 249 ms 24884 KB Output is correct
17 Correct 229 ms 24828 KB Output is correct
18 Correct 139 ms 24796 KB Output is correct
19 Correct 86 ms 24880 KB Output is correct
20 Correct 13 ms 16240 KB Output is correct
21 Correct 29 ms 16168 KB Output is correct
22 Correct 273 ms 24808 KB Output is correct
23 Correct 366 ms 20224 KB Output is correct
24 Correct 243 ms 20364 KB Output is correct
25 Correct 193 ms 24812 KB Output is correct
26 Correct 286 ms 24972 KB Output is correct
27 Correct 179 ms 16540 KB Output is correct
28 Correct 273 ms 16672 KB Output is correct
29 Correct 356 ms 21044 KB Output is correct
30 Correct 166 ms 16408 KB Output is correct
31 Correct 83 ms 20268 KB Output is correct
32 Correct 186 ms 25632 KB Output is correct
33 Correct 259 ms 24788 KB Output is correct
34 Correct 33 ms 17968 KB Output is correct
35 Correct 179 ms 16408 KB Output is correct