codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1351C.md (1298B)


      1 Source: https://codeforces.com/problemset/problem/1351/C
      2 
      3 C. Skier
      4 
      5 time limit per test
      6 
      7 1 second
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 Skier rides on a snowy field. Its movements can be described by a string of characters 'S', 'N', 'W', 'E' (which correspond to $1$ meter movement in the south, north, west or east direction respectively).
     22 
     23 It is known that if he moves along a previously unvisited segment of a path (i.e. this segment of the path is visited the first time), then the time of such movement is $5$ seconds. If he rolls along previously visited segment of a path (i.e., this segment of the path has been covered by his path before), then it takes $1$ second.
     24 
     25 Find the skier's time to roll all the path.
     26 
     27 Input
     28 
     29 The first line contains an integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the input. Then $t$ test cases follow.
     30 
     31 Each set is given by one nonempty string of the characters 'S', 'N', 'W', 'E'. The length of the string does not exceed $10^5$ characters.
     32 
     33 The sum of the lengths of $t$ given lines over all test cases in the input does not exceed $10^5$.
     34 
     35 Output
     36 
     37 For each test case, print the desired path time in seconds.
     38 
     39 Example
     40 
     41 Input
     42 
     43 ```
     44 5
     45 NNN
     46 NS
     47 WWEN
     48 WWEE
     49 NWNWS
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 15
     56 6
     57 16
     58 12
     59 25
     60 ```