1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
   | #include <iostream> #include <queue>
  #define endl '\n'
  using namespace std;
  struct Node { 	int z, x, y, t, k, v; };
  const int H = 165; const int N = 405;
  int h, n, m, v, w; int a[H][N][N], sz, sx, sy; queue<Node> q; bool inq[H][N][N]; int dz[6]{-1, 1, 0, 0, 0, 0}, dx[6]{0, 0, -1, 0, 1, 0}, dy[6]{0, 0, 0, 1, 0, -1};
  int bfs() { 	int k = a[sz][sx][sy] == 5 ? 1 : 0; 	q.push({sz, sx, sy, 0, k, v}); 	inq[sz][sx][sy] = true; 	Node p; 	 	while (q.size()) { 		p = q.front(); 		q.pop(); 		 		for (int i = 0; i < 6; ++i) { 			int nz = p.z + dz[i]; 			int nx = p.x + dx[i]; 			int ny = p.y + dy[i]; 			int nt = p.t + 1; 			int nk = p.k; 			int nv = p.v; 			 			if (nz < 1 || nz > h) continue; 			if (nx < 1 || nx > n || ny < 1 || ny > m) { 				return nt; 			} 			if (inq[nz][nx][ny]) continue; 			if (a[nz][nx][ny] == 2) continue; 			if (a[nz][nx][ny] == 3) { 				if (nv >= w) { 					nv -= w; 				} else { 					continue; 				} 			} else if (a[nz][nx][ny] == 4) { 				if (nk) { 					--nk; 				} else { 					continue; 				} 			} else if (a[nz][nx][ny] == 5) { 				++nk; 			} 			 			q.push({nz, nx, ny, nt, nk, nv}); 			inq[nz][nx][ny] = true; 		} 	} 	 	return 0; }
  int main() { 	ios::sync_with_stdio(false); 	cin.tie(nullptr), cout.tie(nullptr); 	 	cin >> h >> n >> m; 	cin >> sz >> sx >> sy; 	cin >> v >> w; 	for (int k = 1; k <= h; ++k) { 		for (int i = 1; i <= n; ++i) { 			for (int j = 1; j <= m; ++j) { 				cin >> a[k][i][j]; 			} 		} 	} 	 	int ans = bfs(); 	if (!ans) { 		cout << "No"; 	} else { 		cout << "Yes" << endl; 		cout << ans; 	} }
   |