ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Kovrov IT > задача:


50516 - Lines

Гость
• Вопросы к жюри (1)

Задачи сборника

• 50413 - Valid Permutations
• 50861 - The largest Student Group
• 50406 - Draw Pattern 178
• 50419 - The longest bitonic sequence
• 50492 - Contest Scoreboard
• 50418 - Student averages
• 50420 - Teachers Sightseeing
• 50445 - Cryptography
• 50516 - Lines
• 50446 - Snake
• 50875 - Take m-out
• 50786 - Top Question
• 50788 - Eight Puzzle
• 50509 - Reading Book
• 50529 - Row to Table
• 50499 - Table to Row
• 50823 - Secret Number

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб.
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