TopCoder problem "ImageRepeat" used in SRM 256 (Division I Level Three)



Problem Statement

    You will be given two grids of pixels, where each pixel has an ASCII value between 32 and 126, inclusive. Your task is to find the size of the largest square subimage that occurs in both grids. A square subimage of size k is a square region of the input covering pixels from (i,j) to (i+k-1,j+k-1). A square subimage of size k exists in both grids if there exists some (i',j') such that the pixel at (i+x,j+y) of imageA has the same value as the pixel at (i'+x,j'+y) of imageB from all non-negative x and y less than k.
 

Definition

    
Class:ImageRepeat
Method:largestSize
Parameters:String[], String[]
Returns:int
Method signature:int largestSize(String[] imageA, String[] imageB)
(be sure your method is public)
    
 

Constraints

-imageA and imageB will each contain between 1 and 50 elements, inclusive.
-Each element of imageA will contain the same number of characters.
-Each element of imageB will contain the same number of characters.
-Each element of imageA and imageB will contain between 1 and 50 characters, inclusive.
-Each character in imageA and imageB will have ASCII value between 32 and 126, inclusive.
 

Examples

0)
    
{"ABC",
 "BCD",
 "CDE"}
{"ABC",
 "BCD",
 "CDE"}
Returns: 3
The images are the same, so there is a square of size 3 that is repeated.
1)
    
{"ABC",
 "BCD",
 "CDE"}
{"ABCXX",
 "BCDXX",
 "CDFXX"}
Returns: 2
2)
    
{"CEBACBABBDCCCACCDCBD",
 "EBAEBCBEBBCCEABEECED",
 "CEAEAEEEADBDEDABDCCB",
 "EDCEACDABDBCBEECACBD",
 "CDCBCBCCBCCCADDCAEDC",
 "ACCBAABABDABEDEACABC",
 "DCCADCACAEBCBCCCEEEB",
 "ACDABCCCBAABBAEBCBDA",
 "BACEEADBBDBAABCCBDBE",
 "AACACCCEEEBEBDCEABAD",
 "CABACEAAEDDEDDAAEDCC",
 "DDCEAEEBBDBEDBACCCAE",
 "CDABEEEDBDEBCEBECEAB",
 "CDBBDDCDCEDBDEEBCEDD",
 "DBDDBCBAEBBCDAECEBDA",
 "DBBBECAECACADAACACEA",
 "BDADACDEECCBABADEDDC",
 "AEBCABCCABCBBCBABBEC",
 "DDCEAEDEDBCBBABBCCBC",
 "DBBEEAEDDCABCEAACBEC"}
{"CBEEADAEDCDDCEBEEADC",
 "BDBDABCBBDBACEACDACA",
 "ABAABDAADBCECDCEAACE",
 "DDBAAAACAAAAECBDAEDA",
 "EEAAABABCDABAEBEABAE",
 "CECADCCEABEBEDCAEABA",
 "DDECACDEECBBCBDDCDAE",
 "CAEAAEDBADEECAACDAAA",
 "EAECECBCDAAEBDECBBAB",
 "CBCDADDDBACEDBBABACC",
 "DCAEAADBEBEACDEDCCEC",
 "ACACCBEACEBBBBEEACEC",
 "DEDEBEEADCAECEBDDBEA",
 "ACACACEADCACEAACEDAD",
 "DCACBEEBCBDEDADACEEC",
 "EDDEDCDCCEDBCCDCABDC",
 "CABECBAEDCACABDDDADD",
 "CAEDAABCCCCDEDAEABDE",
 "CCDACADABADECDEACCED",
 "BEDADAADACAABAAEBADB"}
Returns: 3

Problem url:

http://www.topcoder.com/stat?c=problem_statement&pm=4692

Problem stats url:

http://www.topcoder.com/tc?module=ProblemDetail&rd=7992&pm=4692

Writer:

lars2520

Testers:

PabloGilberto , brett1479 , Olexiy

Problem categories:

Search