HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50515 - Lines - Revisited

Guest
• Review clarifications (1)

Volume problems

• 50499 - Table to Row
• 50823 - Secret Number
• 50853 - Parking Place
• 50496 - Falling Bricks
• 50802 - Comparing Exams
• 50785 - Swimming Contest
• 50866 - Buy the cheapest
• 50517 - Confusion Matrix
• 50515 - Lines - Revisited
• 50999 - Overlapping Trips
• 50507 - Sequential Numbers
• 50449 - The biggest result
• 50442 - Polynomial Addition
• 50434 - Row Min Subtraction
• 50870 - ZScore normalization
• 50869 - Birthday Celebration
• 50821 - Derivative of an array

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Question by Ibrahim Mesecan.

Lines - Revisited

It’s not only your brother, but many other people liked your snake game. And now you have a fan club. They are desperately waiting for your second fun game: Lines to finish. In this game every time one random color ball at a time (in original game three balls) appear on random positions of the board. Numbers from 1 to 9 represent the 9 colors. The balls disappear and you get points if you can put five or more balls adjacent to each other in any 4 directions: Up, Down, Right and Left (in original game in any 8 directions). Your duty is to remove as much balls as possible. Otherwise, the board will be filled by balls soon and the game will be over. Every time the balls disappear, the player gets 2 points for each ball disappearing (5 balls 10 points, 6 balls 12 points, etc.).

Columns of the board represent x coordinate. So, x increases from left to right, and y increases when going down.

Question: You will be given an initial board configuration, then, you will also be given information for k new balls and k movements. You are asked to calculate the points collected at the end of the game. Note: You don't need to check for the points from initial configuration, calculate only the points by the appearance of new balls and movements given.

Input specification
In the beginning you will be given an integer: the size of the board (n x n) where 5 ≤ n ≤ 25. Then in the following n lines you will be given n integers which are between 0 and 9. Zero represents an empty slot, the number 1 through 9 represent 9 different color balls. Then you will be given number of movements (k) and 1 ≤ k ≤ 30. And in the following k lines, you will be given 7 (3+4) numbers:

  • The first 3 number are for the new ball
    • first number is the color of the new ball
    • the other two numbers are the coordinates where the new ball appears
  • Then you will be given 4 numbers: initial and final (x,y) coordinates of the ball that player moves.

Output specification
Show the total points collected. Note: The initial configuration doesn’t have any points (doesn’t have any balls on a line).

Sample Input I
7
0 0 3 0 0 0 0
0 0 0 3 0 0 0
0 0 0 5 5 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 5 5 4 0
0 0 0 0 3 0 0
5
5 5 4 5 7 3 2
3 6 2 3 1 5 2
5 5 5 6 6 1 2
3 1 5 1 5 7 2
7 2 4 4 3 5 2
Sample Output I
20



Äëÿ îòïðàâêè ðåøåíèé íåîáõîäèìî âûïîëíèòü âõîä.

www.contester.ru