CityMap
SRM 574 · 2012-12-13 · by gojira_tc
Problem Statement
It was later when Manao noticed that the map lacked a legend. The map legend is the list of all types of points of interest (further referred to as POIs) present on the map. Each POI type is coupled with the corresponding symbol denoting this type on the map. For example, you might have seen an 'M' sign denoting a metro station or a fork-and-spoon sign denoting a restaurant on a city map.
Fortunately, not all is lost: the map contains a legend summary. The summary states how many POIs of each type are there on the map (for example, it could say: all in all, there are 9 restaurants and 4 metro stations on the map). Moreover, it turned out that all quantities are pairwise distinct. Manao realized that he could guess the signs using this information (for instance, if there were 4 triangle signs on the map Manao would know that triangle stands for a metro station).
You are given a
You are also given a
For each POI type, determine the letter with which it is denoted on the map. Return a
Constraints
- cityMap will contain between 1 and 50 elements, inclusive.
- Each element of cityMap will be between 1 and 50 characters long, inclusive.
- The elements of cityMap will be of the same length.
- Elements of cityMap will consist of '.' and 'A'-'Z' characters only.
- POIs will contain between 1 and 26 elements, inclusive.
- Each element of POIs will be between 1 and 2500, inclusive.
- All elements of POIs will be distinct.
- There will exist a valid assignment of letters in cityMap to POI types.
{"M....M",
"...R.M",
"R..R.R"}
{3, 4}
Returns: "MR"
The city map is 3 squares high and 6 squares wide. There are 3 'M' signs and 4 'R' signs on the map. The legend summary states that there are three POIs of type 0 and four POIs of type 1 on the map. Obviously, the former are denoted with 'M' on the map and the latter are denoted with 'R'.
{"XXXXXXXZXYYY"}
{1, 8, 3}
Returns: "ZXY"
There is a single 'Z' on the map, thus the legend should state that POIs of type 0 are denoted with 'Z'. There are three 'Y's on the map, therefore POIs of type 2 are surely denoted with 'Y'. Finally, it's now obvious that 'X's stand for the POIs of type 1.
{"...........",
"...........",
"...........",
"..........T"}
{1}
Returns: "T"
The poor city has only one point of interest in the farmost corner.
{"AIAAARRI.......GOAI.",
".O..AIIGI.OAAAGI.A.I",
".A.IAAAARI..AI.AAGR.",
"....IAI..AOIGA.GAIA.",
"I.AIIIAG...GAR.IIAGA",
"IA.AOA....I....I.GAA",
"IOIGRAAAO.AI.AA.RAAA",
"AI.AAA.AIR.AGRIAAG..",
"AAAAIAAAI...AAG.RGRA",
".J.IA...G.A.AA.II.AA"}
{16,7,1,35,11,66}
Returns: "GOJIRA"
{"C"}
{1}
Returns: "C"
Submissions are judged against all 72 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class CityMap with a public method string getLegend(vector<string> cityMap, vector<int> POIs) · 72 test cases · 2 s / 256 MB per case