A - 往復パトロール / Round-Trip Patrol Editorial by admin
Qwen3-Coder-480BOverview
This problem asks you to calculate the total travel time for patrols that involve going back and forth across \(N\) checkpoints arranged in a straight line.
Analysis
Takahashi must travel from checkpoint \(N\) (the waiting station) to checkpoint \(1\) each time, and then return to the waiting station. The one-way travel distance covers \(N - 1\) checkpoints, so a round trip takes \(2(N - 1)\) seconds.
Since the alarm rings \(M\) times, this “round trip” is performed \(M\) times, so the total time is simply \(2(N - 1) \times M\).
A naive approach, such as simulating and adding up the travel time for each alarm, would result in TLE (Time Limit Exceeded) since \(M\) can be up to \(10^9\). However, since the pattern is fixed in this problem, we can compute the answer directly using a formula.
Algorithm
- Read \(N\) and \(M\) from the input.
- Calculate the total time by multiplying the round trip time \(2(N - 1)\) by the number of alarms \(M\).
- Output the result.
This is a simple arithmetic calculation, and there is no need to use loops.
Complexity
- Time complexity: \(O(1)\)
- Space complexity: \(O(1)\)
Implementation Notes
- No particularly difficult algorithms are needed. Just read the input and compute using the given formula.
- The range of values (on the order of \(10^9\)) requires attention to overflow, but this is not an issue in Python.
## Source Code
```python
N, M = map(int, input().split())
total_time = 2 * (N - 1) * M
print(total_time)
This editorial was generated by qwen3-coder-480b.
posted:
last update: