CF750B.New Year and North Pole

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.

Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move t__i kilometers in the direction represented by a string dir__i that is one of: "North", "South", "West", "East".

Limak isn’t sure whether the description is valid. You must help him to check the following conditions:

  • If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South.
  • If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North.
  • The journey must end on the North Pole.

Check if the above conditions are satisfied and print "YES" or "NO" on a single line.

本题中,我们假设地球是一个完美的球体,其表面是一个标准的球面。赤道与任意一条经线的长度均为恰好 40 000 千米。因此,从北极到南极(或反之)的行程恰好为 20 000 千米。

一只北极熊 Limak 居住在北极。在新年临近时,他帮助他人向世界各地派送包裹。他并未获得需要访问地点的坐标,而是得到了一份移动说明——该说明描述了他从北极出发后应如何行进。该说明由 nn 个部分组成。在第 ii 个阶段中,Limak 应沿字符串 diridir_i 所表示的方向行走 tit_i 千米;其中 diridir_i 是以下四个字符串之一:“North”(北)、“South”(南)、“West”(西)、“East”(东)。

Limak 不确定该说明是否有效。你需要帮他验证以下条件:

  • 在任意时刻(包括所有指令开始前,或执行某条指令的过程中),若 Limak 位于北极,则他只能向南移动;
  • 在任意时刻(包括所有指令开始前,或执行某条指令的过程中),若 Limak 位于南极,则他只能向北移动;
  • 整个旅程必须终止于北极。

请检查上述条件是否全部满足,并在单独一行中输出 "YES" 或 "NO"。

输入格式

The first line of the input contains a single integer n (1 ≤ n ≤ 50).

The i-th of next n lines contains an integer t__i and a string dir__i (1 ≤ t__i ≤ 106, ) — the length and the direction of the i-th part of the journey, according to the description Limak got.

输入的第一行包含一个整数 nn(1≤n≤501 \leq n \leq 50)。

接下来的 nn 行中,第 ii 行包含一个整数 tit_i 和一个字符串 diridir_i(1≤ti≤1061 \leq t_i \leq 10^6,),表示 Limak 所获描述中旅程第 ii 段的长度和方向。

输出格式

Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.

如果描述满足这三个条件,则输出 "YES",否则输出 "NO"(均不带引号)。

输入输出样例

  • 输入#1

    5
    7500 South
    10000 East
    3500 North
    4444 West
    4000 North

    输出#1

    YES
  • 输入#2

    2
    15000 South
    4000 East

    输出#2

    NO
  • 输入#3

    5
    20000 South
    1000 North
    1000000 West
    9000 North
    10000 North

    输出#3

    YES
  • 输入#4

    3
    20000 South
    10 East
    20000 North

    输出#4

    NO
  • 输入#5

    2
    1000 North
    1000 South

    输出#5

    NO
  • 输入#6

    4
    50 South
    50 North
    15000 South
    15000 North

    输出#6

    YES

说明/提示

Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole.

下面的示意图展示了 Limak 在前两个样例中的行程。在第二个样例中,答案为“NO”,因为他最终并未回到北极点。

输入解题思路,AI测评打分。不知道怎么写?

首页