F: Flower Garden

https://open.kattis.com/problems/flowergarden

First, construct a prime sieve (this can be shared across all test cases) for the first 20,000 numbers.

Next, simulate Yraglac's walk from one flower to the next to determine the max number of flowers xx he can water before exceeding DD. To do this, keep track of Yraglac's current (x,y)(x,y) and total distance walked so far, and for each flower (xf,yf)(x_f,y_f) add (xxf)2+(yyf)2 \sqrt{(x-x_f)^2+(y-y_f)^2} to the total distance and update Yraglac's current position to (xf,yf)(x_f,y_f) . Break once the total distance exceeds DD.

Finally, count down from xx until hitting a prime number (using the prime sieve to check) or 0, and return that value.

Last updated