#PU593. USACO 2016 January Contest, Bronze — Problem 3. Mowing the Field

    ID: 1448 传统题 文件IO:mowing 2000ms 256MiB 尝试: 0 已通过: 0 难度: 普及 上传者: 标签>USACO赛事:jan16来源:usaco.orgscoring:equal_test_cases模拟

USACO 2016 January Contest, Bronze — Problem 3. Mowing the Field

USACO 2016 January Contest, Bronze — Problem 3. Mowing the Field

题目描述

Farmer John is quite reliable in all aspects of managing his farm, except one: he is terrible at mowing the grass in a timely or logical fashion. The farm is a large 2D grid of square unit cells. FJ starts in one of these cells at time t=0t = 0, mowing the grass in this cell so that it is initially the only cell in which the grass is cut. FJ's remaining mowing pattern is described by a sequence of NN statements. For example, if the first statement is "W 10", then for times t=1t = 1 through t=10t = 10 (i.e., the next 10 units of time), FJ will step one cell to his west, mowing the grass along the way. After completing this sequence of steps, he will end up 10 cells to his west at time t=10t = 10, having mowed the grass in every cell along the way. So slow is FJ's progress that some of the grass he mows might grow back before he is finished with all his mowing. Any section of grass that is cut at time tt will reappear at time t+xt + x. FJ's mowing pattern might have him re-visit the same cell multiple times, but he remarks that he never encounters a cell in which the grass is already cut. That is, every time he visits a cell, his most recent visit to that same cell must have been at least xx units of time earlier, in order for the grass to have grown back. Please determine the maximum possible value of xx so that FJ's observation remains valid.

输入格式

The first line of input contains NN (1≤N≤1001 \leq N \leq 100). Each of the remaining NN lines contains a single statement and is of the form 'D S', where D is a character describing a direction (N=north, E=east, S=south, W=west) and S is the number of steps taken in that direction (1≤S≤101 \leq S \leq 10).

输出格式

Please determine the maximum value of xx such that FJ never steps on a cell with cut grass. If FJ never visits any cell more than once, please

数据范围

(见题面原文)

样例

样例 1

6
N 10
E 2
S 3
W 4
S 5
E 8
10
In this example, FJ steps on a cell at time 17 that he stepped on earlier at
time 7; therefore, $x$ must be at most 10 or else the grass from his first visit
would not yet have grown back.  He also steps on a cell at time 26 that he also
visited at time 2; hence $x$ must also be at most 24.  Since the first of these
two constraints is tighter, we see that $x$ can be at most 10.
Problem credits: Brian Dean