Editorial for Codeforces Round #910 (Div. 2)

Правка en42, от BULLMCHOW, 2023-11-18 18:33:19

1779A - Hall of Fame

Author: n0sk1ll

Hint
Solution
Bonus

1779B - MKnez's ConstructiveForces Task

Author: BULLMCHOW & n0sk1ll

Hint
Solution
Bonus

1779C - Least Prefix Sum

Author: n0sk1ll

Hint
Solution
Bonus

1779D - Boris and His Amazing Haircut

Author: n0sk1ll

Hint
Solution
Bonus

1779B - MKnez's ConstructiveForces Task

Author: BULLMCHOW & n0sk1ll

Hint
Solution
Bonus

1779F - Xorcerer's Stones

Author: n0sk1ll

To solve the problem for matrices of $$$3$$$-rd type, find the shortest path to $$$2$$$ closest exits with a modification of BFS. Block all cells not belonging to the path with obstacles.

For a matrix of type $$$1$$$, Misha can block all empty cells (except the one Vova stands on).

For a matrix of type $$$2$$$, Misha finds the shortest path to some exit with a single BFS and then blocks every other cell.

Matrices of type $$$3$$$ are more complicated. We want to find two shortest paths to the two closest exits and block the remaining empty cells.

But, notice how the paths will likely share their beginnings. We do not have to count those cells twice. Let's take a look at the junction where the two paths merge. If we first fix the junction, finding the shortest path to Vova can be done by running a single BFS and precalculating the shortest distances from each cell to Vova. Finding the shortest path from the junction to the two closest exits can also be done with BFS and precalculation. We modify the BFS, making it multi-source, with a source in each exit. Also, we will allow each cell to be visited twice (but by different exits). We will need to maintain the following data for each cell:

  • How many times was it visited;
  • The last exit/source that visited it;
  • The sum of paths from all exits/sources that visited the cell so far.

Running the BFS with proper implementation produces the answer. When everything said is precalculated, we fix the junction in $$$O(nm)$$$ ways (each empty cell can be a valid junction), and then calculate the shortest path from Vova to the two closest cells in $$$O(1)$$$ per junction.

Total complexity is $$$O(nm)$$$.

Solve the problem with LCA, or report that such solution does not exist.

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en80 Английский n0sk1ll 2023-11-19 19:35:24 0 (published)
en79 Английский n0sk1ll 2023-11-19 19:25:25 2 Tiny change: '## [1898B *-* Milic' -> '## [1898A *-* Milic'
en78 Английский n0sk1ll 2023-11-19 19:25:02 71
en77 Английский n0sk1ll 2023-11-19 19:24:46 67
en76 Английский n0sk1ll 2023-11-19 19:24:15 9 Tiny change: '## [1898B ‐ Milica and' -> '## [1898B-Milica and'
en75 Английский n0sk1ll 2023-11-19 19:23:54 1 Tiny change: '# [1898B — Mili' -> '# [1898B ‐ Mili'
en74 Английский n0sk1ll 2023-11-19 19:22:13 76
en73 Английский n0sk1ll 2023-11-19 19:19:56 1 Tiny change: 'oblem:1898A]\n\nAuth' -> 'oblem:1898 A]\n\nAuth'
en72 Английский n0sk1ll 2023-11-19 19:19:39 2 Tiny change: 'roblem:1897A]\n\nAuth' -> 'roblem:1898A]\n\nAuth'
en71 Английский n0sk1ll 2023-11-19 19:15:37 2 Tiny change: 'roblem:1898A]\n\nAuth' -> 'roblem:1897A]\n\nAuth'
en70 Английский n0sk1ll 2023-11-19 19:15:22 4 Tiny change: '[problem:12A]\n\nAuth' -> '[problem:1898A]\n\nAuth'
en69 Английский n0sk1ll 2023-11-19 19:07:55 4 Tiny change: '[problem:1898A]\n\nAuth' -> '[problem:12A]\n\nAuth'
en68 Английский n0sk1ll 2023-11-19 19:06:58 4 Tiny change: '[problem:12A]\n\nAuth' -> '[problem:1898A]\n\nAuth'
en67 Английский n0sk1ll 2023-11-19 19:06:40 4 Tiny change: '[problem:1898A]\n\nAuth' -> '[problem:12A]\n\nAuth'
en66 Английский n0sk1ll 2023-11-19 19:06:25 0 Tiny change: '## [problem:1898A]\n\nAuthor' -> '## \n\nAuthor'
en65 Английский n0sk1ll 2023-11-19 16:41:26 0 Tiny change: '## [problem:1' -> '[problem:1'
en64 Английский n0sk1ll 2023-11-19 16:39:45 24
en63 Английский n0sk1ll 2023-11-19 11:58:57 56
en62 Английский n0sk1ll 2023-11-18 22:23:08 6 Tiny change: '<j_1$.\n\nOverall com' -> '<j_1$.\n\nThe overall com'
en61 Английский n0sk1ll 2023-11-18 22:22:32 2 Tiny change: 'bet size (\alpha=26 in this p' -> 'bet size ($\alpha=26$ in this p'
en60 Английский n0sk1ll 2023-11-18 22:22:00 111
en59 Английский n0sk1ll 2023-11-18 22:11:55 12 Tiny change: 'ater than the secon' -> 'ater than or equal to the secon'
en58 Английский n0sk1ll 2023-11-18 22:11:19 4
en57 Английский n0sk1ll 2023-11-18 22:10:39 36
en56 Английский n0sk1ll 2023-11-18 22:09:53 1387
en55 Английский BULLMCHOW 2023-11-18 20:12:16 57
en54 Английский BULLMCHOW 2023-11-18 20:10:22 244
en53 Английский BULLMCHOW 2023-11-18 20:05:00 17
en52 Английский BULLMCHOW 2023-11-18 19:57:53 3
en51 Английский BULLMCHOW 2023-11-18 19:56:55 4 Tiny change: ' $s_j$ to the position ' -> ' $s_j$ to position '
en50 Английский BULLMCHOW 2023-11-18 19:54:02 9
en49 Английский BULLMCHOW 2023-11-18 19:52:28 2
en48 Английский BULLMCHOW 2023-11-18 19:52:28 0
en47 Английский BULLMCHOW 2023-11-18 19:52:28 2217
en46 Английский BULLMCHOW 2023-11-18 18:36:42 129
en45 Английский BULLMCHOW 2023-11-18 18:35:05 1924
en44 Английский BULLMCHOW 2023-11-18 18:34:10 1934 Reverted to en39
en43 Английский BULLMCHOW 2023-11-18 18:34:01 1600 Reverted to en41
en42 Английский BULLMCHOW 2023-11-18 18:33:19 2064
en41 Английский BULLMCHOW 2023-11-18 18:32:23 181
en40 Английский BULLMCHOW 2023-11-18 18:31:35 1997
en39 Английский n0sk1ll 2023-11-18 12:10:56 2 Tiny change: 'bilities. implementin' -> 'bilities. Implementin'
en38 Английский n0sk1ll 2023-11-18 12:07:00 7 Tiny change: 'd $j$, we simply find the ' -> 'd $j$, we find the '
en37 Английский n0sk1ll 2023-11-18 12:02:57 230
en36 Английский n0sk1ll 2023-11-15 23:17:37 45
en35 Английский n0sk1ll 2023-11-15 23:13:25 89
en34 Английский n0sk1ll 2023-11-15 23:11:36 54
en33 Английский n0sk1ll 2023-11-15 23:09:36 16 Tiny change: ' times as it should (and try ' -> ' times as necessary (and try '
en32 Английский n0sk1ll 2023-11-15 23:08:30 1332
en31 Английский n0sk1ll 2023-11-15 15:15:36 56
en30 Английский n0sk1ll 2023-11-15 15:12:25 2056
en29 Английский n0sk1ll 2023-11-13 21:55:30 2 Tiny change: 'ed in the *hint* section.\' -> 'ed in the hint section.\'
en28 Английский n0sk1ll 2023-11-13 21:53:55 155
en27 Английский n0sk1ll 2023-11-13 21:48:01 1519
en26 Английский n0sk1ll 2023-11-12 21:14:31 235
en25 Английский n0sk1ll 2023-11-12 21:11:13 57
en24 Английский n0sk1ll 2023-11-12 21:09:33 147
en23 Английский n0sk1ll 2023-11-12 21:04:05 643
en22 Английский n0sk1ll 2023-11-12 20:41:57 2562
en21 Английский n0sk1ll 2023-10-07 22:46:21 107
en20 Английский n0sk1ll 2023-10-07 22:44:30 38
en19 Английский n0sk1ll 2023-10-07 22:43:16 50
en18 Английский n0sk1ll 2023-10-07 22:39:42 2817 Tiny change: ' \equiv x (\mod p)$' -> ' \equiv x \ (\mod p)$'
en17 Английский n0sk1ll 2023-10-02 10:44:23 230
en16 Английский BULLMCHOW 2023-10-02 09:32:30 37 Tiny change: ' of $a_i$ after th' -> ' of $a_i$ to $\lfloor \frac{a_i}{m+1} \rfloor$ after th'
en15 Английский BULLMCHOW 2023-10-01 18:39:16 23
en14 Английский BULLMCHOW 2023-10-01 18:36:19 8 Tiny change: ' $a_i$ be divided into in' -> ' $a_i$ be splited into in'
en13 Английский BULLMCHOW 2023-10-01 18:32:14 224
en12 Английский BULLMCHOW 2023-10-01 18:24:48 5 Tiny change: 'we will solve the array' -> 'we will sort the array'
en11 Английский BULLMCHOW 2023-10-01 18:24:10 824
en10 Английский BULLMCHOW 2023-10-01 17:59:57 4
en9 Английский BULLMCHOW 2023-10-01 17:58:00 11 Tiny change: '>\nAfter every operation the number of' -> '>\nAfter each operation number of'
en8 Английский BULLMCHOW 2023-10-01 17:57:04 105
en7 Английский BULLMCHOW 2023-10-01 17:56:27 279
en6 Английский BULLMCHOW 2023-10-01 17:47:08 25
en5 Английский BULLMCHOW 2023-10-01 17:43:48 7 Tiny change: ' subarray left from $a_' -> ' subarray right from $a_'
en4 Английский BULLMCHOW 2023-10-01 17:42:48 189
en3 Английский BULLMCHOW 2023-10-01 17:33:21 45
en2 Английский n0sk1ll 2023-10-01 14:34:31 239
en1 Английский n0sk1ll 2023-10-01 14:31:01 1091 Initial revision (saved to drafts)