GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Monday, 18 July 2022

[Solution] Making Towers Codeforces Solution


B. Making Towers
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

You have a sequence of n colored blocks. The color of the i-th block is ci, an integer between 1 and n.

You will place the blocks down in sequence on an infinite coordinate grid in the following way.

  1. Initially, you place block 1 at (0,0).
  2. For 2in, if the (i1)-th block is placed at position (x,y), then the i-th block can be placed at one of positions (x+1,y)(x1,y)(x,y+1) (but not at position (x,y1)), as long no previous block was placed at that position.

tower is formed by s blocks such that they are placed at positions (x,y),(x,y+1),,(x,y+s1) for some position (x,y) and integer s. The size of the tower is s, the number of blocks in it. A tower of color r is a tower such that all blocks in it have the color r.

For each color r from 1 to n, solve the following

Solution Click Below:-  👉CLICK HERE

 problem independently:

  • Find the maximum size of a tower of color r that you can form by placing down the blocks according to the rules.
Input

The first line contains a single integer t (1t104) — the number of test cases.

The first line of each test case contains a single integer n (1n105).

The second line of each test case contains n integers c1,c2,,cn (1cin).

Another String Minimization Problem Codeforces Solution

Making Towers Codeforces Solution

Qpwoeirut And The City Codeforces Solution

Chopping Carrots (Easy Version) Codeforces Solution

Chopping Carrots (Hard Version) Codeforces Solution

It is guaranteed that the sum of n over all test cases does not exceed 2105.

Output

For each test case, output n integers. The r-th of them should be the maximum size of an tower of color r you can form by following the given rules. If you cannot form any tower of color r, the r-th integer should be 0.

No comments:

Post a Comment