Https://codeforces.com/contest/1064/problem/D
The match was made with an AC-capable code, then the feeling vector
would time out, then re-handed a copy, opened a very large static array, system test directly exploded ML.
But it's useless to say anything after the game, right?
Test instructions
There is a maze, you can go up and down, but require the number of left to go not more than \ (x\), the number of right walk not more than \ (y\), ask how many points can be reached from the beginning.
Exercises
The game stared for a while the sample casually yy a greedy, but will not testify ...
A point can be reached when and only if there is a path to the left no more than \ (x\) , the right number of times does not exceed the path of \ (y\) ... Does it sound fake?
Direct running Dijkstra seems rather virtual, with the base heap can be hard godless past.
But I'm a stupid x didn't notice the edge right only \ (0\) and \ (1\), the direct double-end queue to run BFS can ...
#include <bits/stdc++.h>using namespace Std;int main () {Ios::sync_with_stdio (false); Cin.tie (0); int N, M, R, C, BL, BR; CIN >> N >> m >> r >> C >> BL >> BR; r--; c--; Vector<string> Board (n); for (int i = 0; i < n; i++) {cin >> board[i]; } Auto get_id = [&] (int x, int y) {return x * m + y; }; vector< vector< Pair<int, Pair<int, int> > > > G (n * m); const int dx[] = {-1, 0, 1, 0}; const int dy[] = {0, 1, 0,-1}; for (int x = 0; x < n; + +) {for (int y = 0; y < m; y++) {if (board[x][y] = = ' * ') {continue; } int me = get_id (x, y); for (int k = 0; k < 4; k++) {int xk = x + dx[k]; int yk = y + dy[k]; if (XK < 0 | | xk >= N | | yk < 0 | | yk >= m | | board[xk][yk] = = ' * ') {continue; } int him = get_id (XK, YK); G[me].push_back ({him, {k = = 3, k = = 1}}); }}} deque<int> Q Q.push_back (get_id (R, c)); const int inf = Numeric_limits<int>::max (); Vector<int> Dist (n * m, INF); DIST[GET_ID (R, c)] = 0; while (!q.empty ()) {int v = q.front (); int d = Dist[v]; Q.pop_front (); for (auto &e:g[v]) {int u = E.first; int w = E.second.first; if (Dist[u] <= D + W) {continue; } if (w = = 0) {q.push_front (U); Dist[u] = D; } else {q.push_back (U); Dist[u] = d + 1; }}} Vector<char> Alive (n * m); for (int i = 0; i < n * m; i++) {Alive[i] = (Dist[i] <= bl); } q.push_back (get_id (R, c)); Fill (Dist.begin (), Dist.end (), INF); DIST[GET_ID (R, c)] = 0; while (!q.empty ()) {int v = q.front (); int d = Dist[v]; Q.pop_front (); for (auto &e:g[v]) {int u = E.first; int w = E.second.second; if (Dist[u] <= D + W) {continue; } if (w = = 0) {q.push_front (U); Dist[u] = D; } else { Q.push_back (U); Dist[u] = d + 1; }}} int ans = 0; for (int i = 0; i < n * m; i++) {if (Alive[i] && dist[i] <= br) {ans++; }} cout << ans << ' \ n '; return 0;}
Codeforces Round #516 Div2 D. Labyrinth