Ice and Fire
All submissions for this problem are available.
Little Johny is a polar bear which lives in arctic region.The bear can hardly tolerate any increase in atmospheric temperature.
After an intra galactic explosion fragments of several meteorites are showered on the entire arctic region in the form of fire bodies.
Little Johny is severely scared of this natural phenomenon as this has caused an considerable increase in temperature of arctic region.
The fire bodies are now randomly distributed on the surface of the arctic region.Poor Johny is now in search of the coolest region for his own
survival.Little Johny has got a unique power that once he found such a region and own it he can have access to all the ice units in that region.
But the cons is that the bear cannot avoid the heat produced by the fire bodies present in that region.Johny has to find the coolest region as soon as possible.
Your task is to find the area of the coolest region that Johny need for his survival.If there are more than one possible coolest regions, then print the one which has maximum area.
Consider the arctic region as a N X M map.Each cell of the map is either represented by "F" or "I" which represents fire and ice respectively.
The magnitude of each "F" or "I" is computed by the following formula :
m= serial number of a particular fire starting from one and counted row wise
im= row number of mth fire starting from 0
jm= column number of mth fire starting from 0
n=serial number of a particular ice starting from one and counted row wise
in=row number of nth ice starting from 0
jn=column number of nth ice starting from 0
P= prime number given for each test case
Note : The region is defined as sub-matrix of the original matrix.
The first line of the input contains the number of test cases T.Then follows T test cases.First line of each test case contains N and M ,the dimensions of the Arctic region.Then follow a N X M character matrix filled with character 'F' or 'I'. The last line of each test case contains an integer P which is basically a prime number.
For each test case output the area of the coolest region required for Little Johny for his survival.If there are more than one possible coolest regions, then print the one which has maximum area.
1<=T<=10 1<=N,M<=100 2<=P<=10^4 and P is a prime number
Input: 2 2 2 FI FI 2 3 4 FIFI IIIF IIFF 23 Output: 2 6
|Time Limit:||0.134483 - 0.204059 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, CLOJ, FS|
Fetching successful submissions