You are given a 1D line of L cells indexed 0..L-1. The end cell is L-1.
There are:
watchers[]
.
players[]
.
flipTimes[]
of integer timestamps.
At each timestamp t in flipTimes, all watchers reverse direction
.
Movement model (discrete time):
t = 0, 1, ..., T-1
.
LEFT
or
RIGHT
).
All watchers start facing LEFT at time 0
.
t
, if
t
is in
flipTimes
, all watchers reverse direction.
t
, a watcher at position
x
:
LEFT
, watches
all cells < x
;
RIGHT
, watches
all cells > x
.
A player is considered
watched
if at least one watcher watches the player’s current cell.
t
, each player tries to move
one cell to the right
(from
p
to
min(p+1, L-1)
),
but if the player is watched at the start of the step, the player cannot move and stays in place
.
LEFT
:
x = max(x-1, 0)
RIGHT
:
x = min(x+1, L-1)
Task:
L-1
.
Notes / clarifications:
flipTimes[]
may contain duplicates and is not sorted.
Write a function that takes (L, watchers, players, T, flipTimes) and returns the count.
Suggested constraints (for implementation):
1 <= L <= 2e5
0 <= W, P <= 2e5
0 <= T <= 2e5
0 <= flipTimes[i] <= T-1