Counting Frog Paths
Practice
3.7 (97 votes)
Algorithms
Easy
Searching
Problem
93% Success 18635 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

There is a frog initially placed at the origin of the coordinate plane. In exactly \(1\) second, the frog can either move up \(1\) unit, move right \(1\) unit, or stay still. In other words, from position \((x,y)\), the frog can spend \(1\) second to move to:

  • \((x+1,y)\)
  • \((x,y+1)\)
  • \((x,y)\)

After \(T\) seconds, a villager who sees the frog reports that the frog lies on or inside a square of side-length \(s\) with coordinates \((X,Y)\), \((X+s,Y)\), \((X,Y+s)\), \((X+s,Y+s)\). Calculate how many points with integer coordinates on or inside this square could be the frog's position after exactly $$T$$ seconds

Input Format:

The first and only line of input contains four space-separated integers: \(X\)\(Y\)\(s\), and \(T\).

Output Format:

Print the number of points with integer coordinates that could be the frog's position after \(T\) seconds.

Constraints:

\(0 \le X,Y \le 100\)

\(1 \le s \le 100\)

\(0 \le T \le 400\)

Note that the Expected Output Feature for Custom Invocation is not supported for this contest. 

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
10 votes
Tags:
MathLinear SearchAlgorithms
Points:20
176 votes
Tags:
Ad-HocApprovedBasic ProgrammingEasyOpen
Points:20
175 votes
Tags:
AlgorithmsEasySearching