HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Contests > CEN112 Homeworks 2013-2015 > problem:


15-SprHW-60. 50516 - Lines

CEN112 Homeworks 2013-2015

Start: Dec.15.2013 at 12:00:00 PM
Finish: Dec.15.2013 at 05:00:00 PM
The contest is finished!
• Contest scoreboard

Guest
• Review clarifications (1)

Contest problems

• 14-Spr1-60. 50647 - Spiral
• 14-Spr2-20. 50442 - Polynomial Add...
• 14-Spr2-40. 50361 - Align Two Lists
• 14-Spr2-50. 50616 - Snake
• 14-Spr2-60. 50444 - n digit kth nu...
• 15-SprHW-20. 50446 - Snake
• 15-SprHW-30. 50788 - Eight Puzzle
• 15-SprHW-40. 50746 - Most Visited
• 15-SprHW-60. 50516 - Lines
• 15-SprPr2-20. 50509 - Reading Book
• 15-SprPr2-60. 50766 - Word Puzzle
• 15-SprPr2-80. 50786 - Top Question
• 15-SprPrE1-20. 50785 - Swimming ...
• 15-SprPrE1-40. 50748 - Gold Store
• 15-SprPrE1-70. 50507 - Sequential ...
• 15-SprResit-20. 50447 - Swimming ...

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

There is a famous game: Lines. In this game, you are given random colored balls on random positions of the board. The player can move one ball at a time and he tries to put the same color balls on a line. If the same color four or more balls are placed adjacent to each other in any four directions: North, South, East and West (in original game, it’s 5 balls in any 8 directions), the balls disappear from the board and the player gets points. Every time the balls are removed from the board, the player gets 2 points for each ball disappearing (4 balls 8 points, 6 balls 12 points, etc.).

Question: You will be given a board configuration. Then the program should define the number of balls adjacent and calculate the points collected. Start checking from the upper left corner.

Input specification
In the beginning you will be given an integer (n) the size of the board where 4 ≤ n ≤ 25. Then in the following n lines, you will be given n integers which are between 0 and 7. Zero represents an empty slot, the numbers 1 through 7 represent 7 different ball colors.

Output specification
Show the total points collected.

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



Для отправки решений необходимо выполнить вход.

www.contester.ru