Menu Close

Find the maximum score obtained at the end of colour chess grid game.

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

EXECUTED USING GCC IN TERMINAL


More Q