CF243C.Colorado Potato Beetle

提高+/省选-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Old MacDonald has a farm and a large potato field, (1010 + 1) × (1010 + 1) square meters in size. The field is divided into square garden beds, each bed takes up one square meter.

Old McDonald knows that the Colorado potato beetle is about to invade his farm and can destroy the entire harvest. To fight the insects, Old McDonald wants to spray some beds with insecticides.

So Old McDonald went to the field, stood at the center of the central field bed and sprayed this bed with insecticides. Now he's going to make a series of movements and spray a few more beds. During each movement Old McDonald moves left, right, up or down the field some integer number of meters. As Old McDonald moves, he sprays all the beds he steps on. In other words, the beds that have any intersection at all with Old McDonald's trajectory, are sprayed with insecticides.

When Old McDonald finished spraying, he wrote out all his movements on a piece of paper. Now he wants to know how many beds won't be infected after the invasion of the Colorado beetles.

It is known that the invasion of the Colorado beetles goes as follows. First some bed on the field border gets infected. Than any bed that hasn't been infected, hasn't been sprayed with insecticides and has a common side with an infected bed, gets infected as well. Help Old McDonald and determine the number of beds that won't be infected by the Colorado potato beetle.

老麦克唐纳有一座农场和一大片马铃薯田,面积为 (1010+1)×(1010+1)(10^{10} + 1) \times (10^{10} + 1) 平方米。该田地被划分为若干个正方形的苗床,每块苗床占据 11 平方米。

老麦克唐纳得知科罗拉多马铃薯甲虫即将入侵他的农场,并可能毁掉全部收成。为了防治这种害虫,他打算对部分苗床喷洒杀虫剂。

于是,老麦克唐纳来到田地中,站在中心苗床的正中心位置,并对该苗床喷洒了杀虫剂。随后,他将进行一系列移动,并喷洒更多苗床。每次移动时,老麦克唐纳在田地上向左、右、上或下移动若干整数米。他在移动过程中会喷洒所有他经过的苗床。换言之,凡与老麦克唐纳移动轨迹存在任意交集(哪怕只是擦过边角)的苗床,均会被喷洒杀虫剂。

老麦克唐纳完成全部喷洒后,将所有移动步骤记录在一张纸上。现在他想知道:在科罗拉多甲虫入侵之后,有多少块苗床不会被感染。

已知科罗拉多甲虫的感染过程如下:首先,田地边界上的某一块苗床被感染;此后,任何尚未被感染、未被喷洒过杀虫剂、且与某块已被感染的苗床有公共边的苗床,也将被感染。请帮助老麦克唐纳计算最终不会被科罗拉多马铃薯甲虫感染的苗床数量。

输入格式

The first line contains an integer n (1 ≤ n ≤ 1000) — the number of Old McDonald's movements.

Next n lines contain the description of Old McDonald's movements. The i-th of these lines describes the i-th movement. Each movement is given in the format "d__i x__i", where d__i is the character that determines the direction of the movement ("L", "R", "U" or "D" for directions "left", "right", "up" and "down", correspondingly), and x__i (1 ≤ x__i ≤ 106) is an integer that determines the number of meters in the movement.

第一行包含一个整数 nn(1≤n≤10001 \leq n \leq 1000)—— 表示老麦当劳的移动次数。

接下来的 nn 行描述老麦当劳的每次移动。其中第 ii 行描述第 ii 次移动。每次移动的格式为 “di xid_i\ x_i”,其中 did_i 是一个字符,表示移动方向(“L”、“R”、“U” 或 “D” 分别对应“左”、“右”、“上”、“下”),而 xix_i(1≤xi≤1061 \leq x_i \leq 10^6)是一个整数,表示该次移动的距离(单位:米)。

输出格式

Print a single integer — the number of beds that won't be infected by the Colorado potato beetle.

Please do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

输出一个整数——未被科罗拉多马铃薯甲虫感染的床铺数量。

在 C++ 中,请勿使用 %lld 说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 说明符。

输入输出样例

  • 输入#1

    5
    R 8
    U 9
    L 9
    D 8
    L 2

    输出#1

    101
  • 输入#2

    7
    R 10
    D 2
    L 7
    U 9
    D 2
    R 3
    D 10

    输出#2

    52

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

首页