Connection Status:
Competition Arena > LimpingDog
SRM 777 · 2020-01-26 · by misof · Simple Math, Simple Search, Iteration, Simulation
Class Name: LimpingDog
Return Type: int
Method Name: countSteps
Arg Types: (int)
Problem Statement

Problem Statement

A limping dog is walking forward. The dog moves one leg at a time, in the following cyclic order: right rear, right front, left rear, left front.

The dog's left rear leg is injured and moving it takes two seconds. A step with any other leg takes only one second.

After every 47 completed steps the dog takes a 42-second break.

You are given the int time. Return the number of steps the dog has completed in the given time.

Constraints

  • time will be between 0 and 10^6, inclusive.
Examples
0)
2
Returns: 2

In the first two seconds the dog made one step with his right rear leg and one step with his right front leg.

1)
3
Returns: 2

After three seconds the dog is in the middle of stepping with his injured left rear leg. Thus, the number of completed steps is still only 2.

2)
6
Returns: 5

In six seconds the dog made five steps: one with each leg, and then again one with the right rear leg.

3)
80
Returns: 47

The dog has made the first 47 steps and it is now right in the middle of its first 42-second rest.

4)
104
Returns: 50

The dog finished its first rest and then it made three more steps. Note that the rest does not reset the order in which the dog moves its legs. The last leg moved before the rest was the injured left rear leg, so the first three steps after the rest are the left front, right rear, and right front leg (taking one second each).

5)
806000
Returns: 376000

The dog has just finished resting and it is ready to take another step.

6)
54321
Returns: 25346

During the first 54321 seconds the dog has rested 539 times, it completed 25346 steps, and it is now in the middle of moving the injured leg again.

Submissions are judged against all 114 archived test cases, of which 7 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class LimpingDog with a public method int countSteps(int time) · 114 test cases · 2 s / 256 MB per case

Submitting as anonymous