Challenge Overview
Problem Statement | ||||||||||||||||||||||||
Twisted is a game played by arranging square tiles in cells of an infinite grid. Each side of the tile is divided into three equal parts by two contacts. Each tile has exactly 4 pieces of wire on it, each piece connects two distinct contacts on the sides of the tile, and each contact has exactly one piece of wire connected to it. Whenever two tiles get placed in vertically or horizontally adjacent cells, matching contacts on the side they share get connected and form a chain of wire. Below you can find several examples of tiles:
You will be given at most N tiles, one by one. You need to place each tile on the board. The first tile is placed automatically in a cell (N, N), without rotation. You have to choose the cells to place each of the following tiles and how much you want to rotate it when placing. The second tile must be placed in a cell adjacent to the cell of the first tile. When the second tile is placed, the main chains are defined as chains of wire which go through one of the contacts on the side shared by the first and the second tiles. The active contacts are the contacts on both ends of the main chains. After the second tile is placed, there can be 1 or 2 main chains and 0, 2 or 4 active contacts. Consider examples below (main chains are drawn in red):
Each tile after the second one must extend one of the main chains, i.e., one of the wires on it must become connected to one of the active contacts: ===> It's also possible to extend more than one main chain in one move: ===> If a new tile is placed so that a wire on it connects an active contact to another chain of wires, this chain becomes part of the main chain as well, and its other end becomes active, while the previously active contact gets deactivated:===> As can be noticed on some of the pictures, as game progresses, two main chains can become merged into one and also each of the main chains can get transformed into a closed loop (that can't be further extended). The game ends either when all N tiles are placed or when there are no active contacts anymore (because all chains on the board are looped). An example of such situation is shown below: Your goal is to achieve as large length of a main chain as possible in the end of the game. The length of a chain is just the number of wires in it, i.e., each single wire is assumed to have a length of 1 disregarding of how it is located within its cell. Your code should implement two methods, as described below:
Your score for a single test case will be equal to the length of the largest main chain present on the board once the game was stopped. Your overall score will be the arithmetic average of your individual scores over all test cases. An offline tester and a separate visualization tool are available. | ||||||||||||||||||||||||
Definition | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
Notes | ||||||||||||||||||||||||
- | The memory limit is 1024 MB and the time limit is 10 seconds (which includes only time spent in your code). | |||||||||||||||||||||||
- | There is no explicit code size limit. The implicit source code size limit is around 1 MB (it is not advisable to submit codes of size close to that or larger). Once your code is compiled, the binary size should not exceed 1 MB. | |||||||||||||||||||||||
- | The compilation time limit is 30 seconds. You can find information about compilers that we use and compilation options here. | |||||||||||||||||||||||
- | There are 10 example test cases and 100 full submission test cases. | |||||||||||||||||||||||
Examples | ||||||||||||||||||||||||
0) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
1) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
2) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
3) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
4) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
5) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
6) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
7) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
8) | ||||||||||||||||||||||||
| ||||||||||||||||||||||||
9) | ||||||||||||||||||||||||
|
This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2020, TopCoder, Inc. All rights reserved.