Connection Status:
Competition Arena > SpidersOnTheGrid
Member SRM 455 · 2009-12-03 · by Seyaua · Simple Search, Iteration
Class Name: SpidersOnTheGrid
Return Type: int
Method Name: find
Arg Types: (vector<string>)
Problem Statement

Problem Statement

Petya likes spiders. He put a spider in each cell of a rectangular grid. He has studied spiders for many years, so he predicted the behaviour of all of the spiders. At the beginning of each second, every spider will move from its cell to one of the adjacent cells (or off the grid). For each cell, he wrote the direction of its movement to matrix which is represented by a String[], A. The j-th character of i-th element of A will be either 'N', 'S', 'E' or 'W' and it will represent north, south, east and west directions of movement, respectively. If a spider moves outside the grid it falls to the floor. Return the number of free cells after 1 second.

Constraints

  • A will contain between 1 and 50 elements, inclusive.
  • Each element of A will contain between 1 and 50 characters, inclusive.
  • All elements of A will have the same number of characters.
  • Each character will be either 'N', 'E', 'S' or 'W'.
Examples
0)
{"EW","NN"}
Returns: 2
1)
{"EEEEEEEEEEEEEEEEEEEEEEEEEEEEEW"}
Returns: 1
2)
{"EW"}
Returns: 0
3)
{"ESW","ENW"}
Returns: 4
4)
{"E"}
Returns: 1

Submissions are judged against all 103 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class SpidersOnTheGrid with a public method int find(vector<string> A) · 103 test cases · 2 s / 256 MB per case

Submitting as anonymous