QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB 満点: 100

#22487. Banner

統計

Bessie is returning from a long trip abroad, and Farmer John wants to erect a nice "Welcome Home" banner in her pasture for her arrival. The banner will hang between two poles on a wire whose length is in the range $L1..L2$ ($1 \le L1 \le L2$; $L1 \le L2 \le 1,500$).

The pasture's size is $W \times H$ ($1 \le W \le 1,000$; $1 \le H \le 1,000$), and Farmer John has installed a post at every point with integer coordinates. Of these $(W + 1) * (H + 1)$ points, Farmer John must pick just two that will hold either end of the wire from which he will hang the banner.

FJ wants no interference with his banner as it hangs and requires that no post be directly under the tight wire he stretches between the two chosen posts.

Farmer John needs your help to figure out how many possible ways he can hang the banner. He knows the number is large and that a 32-bit integer might not be sufficient to compute the answer.

Consider the example pasture below, with $W = 2$ and $H = 1$:

       * * *
       * * *

The banner size is in the range 2..3. This pasture contains $(2+1) * (1+1) = 6$ points and has $(6 \text{ take } 2) = (6*5)/(2*1) = 15$ different potential pairs of points between which the banner-holding wire might stretch:

   (0,0)-(0,1)   (0,0)-(2,1)   (0,1)-(2,1)   (1,1)-(2,0)
   (0,0)-(1,0)   (0,1)-(1,0)   (1,0)-(1,1)   (1,1)-(2,1)
   (0,0)-(1,1)   (0,1)-(1,1)   (1,0)-(2,0)   (2,0)-(2,1)
   (0,0)-(2,0)   (0,1)-(2,0)   (1,0)-(2,1)

Of these pairs, only four have a length in the range $2..3$:

                     Len                       Len
        (0,0)-(2,0) 2.00          (0,1)-(2,0) 2.24 
        (0,0)-(2,1) 2.24          (0,1)-(2,1) 2.00

Of these four, the pairs (0,0)-(2,0) and (0,1)-(2,1) both have a post directly on the line between the endpoints, and thus are unsuitable.

So, just two pairs of points out of 15 are acceptable candidates for hanging the banner wire.

Input

  • Line 1: Four space-separated integers: $W$, $H$, $L1$, and $L2$

Output

  • Line 1: A single integer denoting the number of possible banners

Examples

Input 1

2 1 2 3

Output 1

2

Problem credits: Nathan Pinsker, 2010

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.