Binita is playing a grid like chess. The game will be played on a rectangular grid consisting of N rows and M columns. Initially all the cells of the grid are uncolored. Binita’s initial score is zero. At each turn, he chooses some cell that is yet not colored, and colors that cell. The score obtained in this step will be number of neighboring colored cells of the cell that Binita colored in this step.
Two cells are neighbors of each other if they share a side between them. The game will end when all the cells are colored. Finally, total score obtained at the end of the game will sum of score obtained in each turn. Binita wants to know what maximum score he can get? Can you please help him in finding this out?
Constraints:
1 ≤ N, M ≤ 50
Input Format:
The Only line of input contains two space-separated integers N, M denoting the dimensions of the grid.
Output Format:
Print the output a single line containing an integer corresponding to the maximal possible score Binita can obtain.
#include <stdio.h> int main() {int n,m,score=0; //printf("Enter the dimensions of the grid : "); scanf("%d%d",&n,&m); score=((n-1)*(m-1)*2+m+n-2); //printf("Max Score : "); printf("%d\n",score); return 0;}
Input_1:
Enter the dimensions of the grid : 15 13
Output:
Max Score : 362
Input_2:
Enter the dimensions of the grid : 21 16
Output:
Max Score : 635
Input_3:
Enter the dimensions of the grid : 16 50
Output:
Max Score : 1534
Input_4:
Enter the dimensions of the grid : 32 20
Output:
Max Score : 1228
ILLUSTRATION
More Q
- Determine if a person could attend all meetings in given interval times.
- Find the volume of a volley ball
- Find the maximum score obtained at the end of colour chess grid game.
- Find the number of pairs if positive integers with condition is even.
- Return the largest subset such that every pair meets the given condition.
- Find the number of index triplets that satisfy given condition.
- Handling multiple queries using array – sum, update, range.
- Find all the sequences that occur more than once in DNA molecule.
- Find the biggest number.
- Sum of cube of each number is again equal to the number then it is an Armstrong number.
- Hello World.
- Calculate the Cube Root.
- Find the count of consecutive 1’s present in array.
- Return an array with athletes relative ranks according to the score.
- Return a string of its base 7 representation.
- Return kth largest element in sorted order.
- Find all repeated elements in the array.
- Find atleast one duplicate number in the array.
- Find the maximum result of = a XOR b.