아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cow Parade

면접 대비

시간 제한1초메모리 제한1024 MB

요약
격자 위를 남북동서로 이동하는 경로가 주어질 때 지나간 서로 다른 거리가 몇 개인지 센다.
난이도

보통10점 중 4점

유형
시뮬레이션, 해시맵, 구현
정답자
아직 제출이 없습니다

문제

Farmer John's cows are participating in the annual Bovington, Wisconsin Cow Parade. The streets in this city form a rectangular grid: they all run north-south or east-west and are equally spaced. Farmer John's cattle parade through the streets.

The cows, being meticulous record keepers, recorded the path of their parade. They wrote exactly a series of D (1 ≤ D ≤ 1,000) directions, such as "north for 3 blocks", then "east for 2 blocks", etc. The distance traveled was always in the range 1..10,000. See the sample data for some of the silly ways the cows recorded their march.

After the parade, the cows wanted to know how many different streets they paraded on. If they paraded on one street, left it, and later paraded on the same street, they only count that street once.

입력

  • Line 1: A single integer, D

  • Lines 2..N+1: Each line describes a sequence part of the parade route and contains:

    • A character representing the direction ('N', 'S', 'E', or 'W')
    • the number of blocks travelled in that direction.

출력

  • Line 1: A single integer containing the number of unique streets visited by the cows.

힌트

[The "N 1", "N 4", and "S 4" are all on the same street. The others are on different unique streets.

예제1

  1. 예제 1

    입력
    6
    N 1
    N 4
    E 2
    S 5
    W 2
    S 4
    
    예상 출력
    4