I: City Destruction

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

  • Let dp[i][0]dp[i][0] denote the (minimum) number of moves required to destroy all the cities from ii through NN, assuming that the (i1)th(i-1)^{th}​city (if exists) was not destroyed before the ithi^{th} city.​

  • Let dp[i][1]dp[i][1] denote the (minimum) number of moves required to destroy all the cities from ii through NN, assuming that the (i1)th(i-1)^{th}​city (if exists) was destroyed before the ithi^{th} city.​

For convenience, set e0=0e_0=0.

  • Initial condition:

    • dp[n][0]=hnddp[n][0]=\lceil \frac{h_n}{d} \rceil, dp[n][1]=max(hnen1,0)ddp[n][1]=\lceil \frac{max(h_n-e_{n-1},0)}{d} \rceil

  • For i<ni<n, it is easy to see that the transitions are

    • dp[i][0]=min(dp[i+1][0]+(max(hiei+1,0)d,dp[i+1][1]+hid))dp[i][0]=min(dp[i+1][0]+\lceil \frac{(max(h_i-e_{i+1},0)}{d} \rceil, dp[i+1][1]+\lceil \frac{h_i}{d} \rceil))

      • If we assume city i+1i+1was destroyed earlier, then our health reduces by ei+1e_{i+1}and the number of extra moves required is (max(hiei+1,0)d\lceil \frac{(max(h_i-e_{i+1},0)}{d} \rceil.

      • Otherwise, the number of extra moves required is hid\lceil \frac{h_i}{d} \rceil.

    • dp[i][1]=min(dp[i+1][0]+(max(hiei+1ei1,0)d,dp[i+1][1]+max(hiei1,0)d))dp[i][1]=min(dp[i+1][0]+\lceil \frac{(max(h_i-e_{i+1}-e_{i-1},0)}{d} \rceil, dp[i+1][1]+\lceil \frac{max(h_i-e_{i-1},0)}{d} \rceil))

      • In this case, since city i1i-1 has exploded already, our health has already reduced to max(hiei1,0)max(h_i-e_{i-1},0).

      • If we assume city i+1i+1was destroyed earlier, then our health reduces by ei+1e_{i+1}and the number of extra moves required is (max(hiei+1ei1,0)d\lceil \frac{(max(h_i-e_{i+1}-e_{i-1},0)}{d} \rceil.

      • Otherwise, the number of extra moves required is max(hiei1,0)d\lceil \frac{max(h_i-e_{i-1},0)}{d} \rceil.

  • The final answer is dp[1][0]dp[1][0].

Last updated