Anda di halaman 1dari 1

You are an alien commander planning to invade various cities.

Each city is composed of a strip of buildings that can be thought of as a 2D arr ay, described by a series of non-negative integers. For example, the numbers 1, 3, 0, 2, 4 describe the following city: O O O O O O O O O O

where O represents a square occupied by a building, and - represents a square no t occupied. You command a set of aliens that act as follows: some initial set of aliens is sent to some set of building squares. At each time interval, an alien spawns in any building square with 2 or more neighbouring (ie. sharing an edge) squares containing aliens. The aliens aim to completely cover the buildings in each city. Your task is to determine the minimum number of aliens that need to be spawned initially to achieve this task in a some finite amount of time. The first line will be an integer 1<=N<=100. N test cases follow. For each test case, you will be given two lines: 1<=M<=10^5, the number of build ings in the city, and numbers B1, B2,..., BM separated by spaces, the heights of each of the build ings, from left to right. As output, print N numbers separated by line breaks, the minimum number of alien s required in each case. Sample Input: 3 1 1 2 2 1 3 2 0 3 Sample Output: 1 2 4

Anda mungkin juga menyukai