Marathon Match 155

Register
Submit a solution
The challenge is finished.

Challenge Overview

Important Links

  • Submission-Review You can find your submissions artifacts here. Artifacts will contain output.txt's for both example test cases and provisional test cases with stdout/stderr and individual test case scores.
  • Other Details For other details like Processing Server Specifications, Submission Queue, Example Test Cases Execution.

Overview

You are given an N*N grid, where each cell contains an arrow in one of 8 compass directions and a multiplier. You need to place a sequence of numbers from 1 to K into the grid cells, such that the arrow in the cell of every number k (less than K) points in the direction of the number k+1. Each number k will give you k*m points, where m is the multiplier in the cell of number k. Your task is to maximize the total points collected.

Here is an example solution for seed=1. White, cyan, yellow and red cells correspond to multipliers 1, 2, 3, and 5, respectively.

example2.gif

Input and Output

Your code will receive as input the following values, each on a separate line:

  • N, the grid size.
  • N*N lines representing the grid in row-major order. Each line will be formatted as "A M" (without the quotes), where A is the arrow id and M is the multiplier number at the given cell. The arrow ids are shown below.

compass_small.png

You must output a sequence of locations for your numbers, formatted as follows:

  • K, number of locations.
  • K lines representing locations, each formatted as "r c" (without the quotes), where r is the row and c is the column. All locations are 0-based.

Scoring

The raw score is the total points obtained from your sequence of numbers. If your return was invalid, then your raw score on this test case will be -1. Possible reasons include:

  • Using fewer than 0 or more than N*N locations.
  • Using locations that are out of bounds or are incorrectly formatted.
  • Using the same location multiple times.
  • Not having the arrows point at the next number in the sequence.
  • Exceeding the time limit.

If your raw score for a test case is negative then your normalized score for that test case is 0. Otherwise, your normalized score for each test case is YOUR/MAX, where YOUR is your raw score and MAX is the largest positive raw score currently obtained on this test case (considering only the last submission from each competitor). Finally, the sum of all your test scores is normalized to 100.

Test Case Generation

Please look at the generate() method in the visualizer's source code for the exact details about test case generation. Each test case is generated as follows:

  • The grid size N is chosen between 8 and 30, inclusive.
  • The probability of the first multiplier P1 is chosen between 0.1 and 0.3, inclusive.
  • The probability of the second multiplier P2 is chosen between 0 and P1, inclusive.
  • The probability of the third multiplier P3 is chosen between 0 and P2, inclusive.
  • Generate the grid. Start with an empty N*N grid. For each cell select an arrow direction at random, ensuring that cells on the border do not have arrows pointing outside the grid. With probability P1 set the cell multiplier to 2, with probability P2 set it to 3, with probability P3 set it to 5, otherwise set it to 1.
  • All values are chosen uniformly at random.

Notes

  • The time limit is 10 seconds per test case (this includes only the time spent in your code). The memory limit is 1024 megabytes.
  • The compilation time limit is 30 seconds.
  • There are 10 example test cases and 100 full submission (provisional) test cases. There will be 2000 test cases in the final testing.
  • The match is rated.

Languages Supported

C#, Java, C++ and Python

Submission Format

Your submission must be a single ZIP file not larger than 500 MB, with your source code only.
Please Note: Please zip only the file. Do not put it inside a folder before zipping, you should directly zip the file.

Make sure you name your Source Code file as Arrows*.<appropriate extension>*

Sample Submissions

Here are example solutions for different languages, modified to be executed with the visualizer. You may modify and submit these example solutions:

Tools

An offline tester is available below. You can use it to test/debug your solution locally. You can also check its source code for an exact implementation of test case generation and score calculation. You can also find links to useful information and sample solutions in several languages.

Downloads

Offline Tester / Visualizer

Your solution should interact with the tester/visualizer by reading data from standard input and writing data to standard output.

To run the tester with your solution, you should run:

java -jar tester.jar -exec "<command>" -seed <seed>

Here, <command> is the command to execute your program, and <seed> is seed for test case generation.
If your compiled solution is an executable file, the command will be the full path to it, for example, "C:\TopCoder\Arrows.exe" or "~/topcoder/Arrows".
In case your compiled solution is to be run with the help of an interpreter, for example, if your program is in Java, the command will be something like "java -cp C:\TopCoder Arrows".

Additionally you can use the following options:

  • -seed <seed> Sets the seed used for test case generation, default is seed 1.
  • -debug. Print debug information.
  • -novis. Turns off visualisation.
  • -pause. Starts the visualizer in paused mode. See more information below.
  • -delay <delay> Sets the delay (in milliseconds) between visualizing consecutive simulation steps, default is 1000.
  • -noanimate. Only show the final state, no intermediate steps.
  • -manual. Play the game manually. Use the left mouse click to place numbers and the right mouse click to undo moves.
  • -showArrow. Shows a blue arrow from the current number to the next number for each move.
  • -N <N> Sets a custom grid size.
  • -P1 <P1> Sets a custom probability for the first multiplier.
  • -P2 <P2> Sets a custom probability for the second multiplier.
  • -P3 <P3> Sets a custom probability for the third multiplier.

The visualizer works in two modes. In regular mode, steps are visualized one after another with a delay specified with the -delay parameter. In paused mode, the next move will be visualized only when you press any key. The space key can be used to switch between regular and paused modes. The default starting mode is regular. You can use the -pause parameter to start in paused mode.

Marathon local testers have many useful options, including running a range of seeds with a single command, running more than one seed at time (multiple threads), controlling time limit, saving input/output/error and loading solution from a file. The usage of these options are described here.