Tap here to switch tabs
Problem
Submissions

Problem: Champagne Tower

med
30 min
Try to solve the Champagne Tower problem.

Statement

Glasses are arranged in a pyramid where the 0th0^{th} row contains 11 glass, the 1st1^{st} row contains 22 glasses, and in general, the rthr^{th} row contains r+1r + 1 glasses. Each glass can hold a maximum of 11 cup of champagne.

Champagne is poured into the top glass at index (0,0)(0, 0). Once a glass becomes completely full, any excess liquid spills over equally into the two glasses directly beneath it: index (r+1,c)(r + 1, c) and index (r+1,c+1)(r + 1, c + 1). When those glasses become full, the excess continues to fall evenly into the glasses below them, and this process repeats down the tower.

Given the total amount of liquid poured, return the amount of champagne in the glass located at index (query_row, query_glass).

Constraints:

  • 0≤0 \leq poured ≤109\leq 10^9

  • 0≤0 \leq query_glass ≤\leq query_row <100< 100

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Champagne Tower

med
30 min
Try to solve the Champagne Tower problem.

Statement

Glasses are arranged in a pyramid where the 0th0^{th} row contains 11 glass, the 1st1^{st} row contains 22 glasses, and in general, the rthr^{th} row contains r+1r + 1 glasses. Each glass can hold a maximum of 11 cup of champagne.

Champagne is poured into the top glass at index (0,0)(0, 0). Once a glass becomes completely full, any excess liquid spills over equally into the two glasses directly beneath it: index (r+1,c)(r + 1, c) and index (r+1,c+1)(r + 1, c + 1). When those glasses become full, the excess continues to fall evenly into the glasses below them, and this process repeats down the tower.

Given the total amount of liquid poured, return the amount of champagne in the glass located at index (query_row, query_glass).

Constraints:

  • 0≤0 \leq poured ≤109\leq 10^9

  • 0≤0 \leq query_glass ≤\leq query_row <100< 100