Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
hackercup / 2023 /finals /transposing_tiles_sol.md
wjomlex's picture
2023 Problems
ff444f7 verified
|
raw
history blame
1.11 kB

Consider all possible initial moves (of swapping one pair of adjacent tiles) and the corresponding score achieved. Note that to calculate the score of (1) swap, it is enough to consider the submatrix of size (7) x (7) centered at one of the tiles being swapped.

One candidate for the answer is a pair of (1)-swaps as long as these swaps are not close to each other (otherwise they might interfere). We also need to consider swaps that are close to each other. For that, consider some tile (A) to be swapped with an adjacent one, and another tile (B) also to be swapped with another adjacent one. It's enough to consider all tiles (B) that are in either the same column or same row as (A), and with a Manhattan distance of at most (2) from (A).

For each tile chosen to be swapped, there are at most (4) tiles adjacent to it. With that, the overall time complexity is (\mathcal{O}(RC(K + \log(RC)))), where (K) is a constant denoting the number (2)-swaps that can be made close to each other as well as checking the score for them. (K) is approximately (7784*4 = 6272).