Official algorithmic problem description and constraints.
ErnKor is ready to do anything for Julen, even to swim through crocodile-infested swamps. We decided to test this love. ErnKor will have to swim across a river with a width of 1 meter and a length of π meters.
The river is very cold. Therefore, in total (that is, throughout the entire swim from 0 to π+1) ErnKor can swim in the water for no more than π meters. For the sake of humanity, we have added not only crocodiles to the river, but also logs on which he can jump. Our test is as follows:
Initially, ErnKor is on the left bank and needs to reach the right bank. They are located at the 0 and π+1 meters respectively. The river can be represented as π segments, each with a length of 1 meter. Each segment contains either a log 'L', a crocodile 'C', or just water 'W'. ErnKor can move as follows:
Determine if ErnKor can reach the right bank.
Detailed video explanations, mathematical intuition, and clean C++ implementation code.