結果

問題 No.1101 鼻水
ユーザー qwewe
提出日時 2025-05-14 13:15:02
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 5,493 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 81,408 KB
最終ジャッジ日時 2025-05-14 13:16:12
合計ジャッジ時間 5,153 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 1 WA * 14 TLE * 1 -- * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import math

# Function to compute ceil(a / b) for integers a, b > 0
# Equivalent to math.ceil(a / b) but avoids floating point issues
def ceil_div(a, b):
    # If a is non-positive, standard ceiling division might behave unexpectedly.
    # Context: we calculate needed_k based on T - time_since_last_sniff.
    # T >= 2. time_since_last_sniff >= 0.
    # If T - time_since_last_sniff <= 0, it means time_since_last_sniff >= T,
    # which is handled by the other branch ('if time_since_last_sniff >= T').
    # So, a = T - time_since_last_sniff will be positive here.
    # V is the divisor, V >= 1.
    # Thus standard integer division applies.
    if b == 0:
        # Avoid division by zero, though V >= 1 constraint prevents this.
        # Should return infinity or handle error based on context.
        # Given V >= 1, this case is impossible.
        raise ValueError("Division by zero")
    # Standard ceiling division formula for positive integers
    return (a + b - 1) // b

def solve():
    V, T, P = map(int, sys.stdin.readline().split())

    # Check the special condition derived from examples
    # If V+1 >= T and P > 0, the total time seems to be (P+1)*(V+1) + 2.
    # This pattern holds for Example 1 and Example 3.
    # Example 2 has V+1 < T, and its output matches the simulation logic below.
    # It also covers the P=0 base case correctly.
    if P > 0 and V + 1 >= T:
        # Use __int128 or arbitrary precision integers if necessary. Python handles large integers automatically.
        result = (P + 1) * (V + 1) + 2
        print(result)
        return

    # If the special condition doesn't apply, use simulation logic.
    # This logic handles V+1 < T cases and the P=0 case.
    
    total_time = 0
    # current_time_marker represents the time point when the mucus level became 0 most recently.
    current_time_marker = 0 
    
    # Initialize last_sniff_time to a value that guarantees the first check passes.
    # Any value <= -T works. Using -T ensures event_time=V will result in time_since_last_sniff >= V + T >= T.
    last_sniff_time = -T 
    
    blows_left = P

    # Simulate the process using P blows
    while blows_left > 0:
        
        # Calculate the time when mucus level reaches V, starting from 0 at current_time_marker
        event_time = current_time_marker + V 
        
        # Check if sniffing is possible based on cooldown T
        time_since_last_sniff = event_time - last_sniff_time
        
        if time_since_last_sniff >= T:
            # Case 1: Sniff is possible. Perform Sniff+Blow cycle.
            # Sniff at event_time, level becomes V-1. Last sniff time updated.
            # Level reaches V again at event_time + 1. Sniff impossible (1 < T). Blow nose.
            # Level becomes 0 at event_time + 1.
            
            time_advancement = V + 1 # Total time advanced in this cycle
            total_time += time_advancement
            current_time_marker += time_advancement # Update marker to time after blow
            last_sniff_time = event_time # Update last sniff time
            blows_left -= 1 # Use one blow
            
        else:
            # Case 2: Sniff is not possible due to cooldown. Perform Blow Only cycle(s).
            # We can potentially perform multiple Blow Only cycles consecutively until
            # either sniff becomes possible again or we run out of blows.
            
            # Minimum number of Blow Only cycles needed until time_since_last_sniff >= T
            # Let k be the number of cycles. After k cycles, event_time increases by k*V.
            # New time_since_last_sniff = (event_time + (k-1)*V) - last_sniff_time.
            # Needs check carefully: The time since last sniff increases by V in each Blow Only cycle.
            # We need k cycles such that initial_time_since_last_sniff + k * V >= T
            
            delta_T_needed = T - time_since_last_sniff # How much more time needs to pass since last sniff
            needed_k = ceil_div(delta_T_needed, V) # Minimum number of Blow Only cycles

            # Number of Blow Only cycles we can actually perform is limited by remaining blows
            k_do = min(blows_left, needed_k)
            
            # Each Blow Only cycle advances time by V
            time_advancement = k_do * V
            total_time += time_advancement
            current_time_marker += time_advancement # Update marker
            blows_left -= k_do # Use k_do blows
            
            # last_sniff_time does not change during Blow Only cycles because no sniff occurred.

    # Final phase: After all P blows are used up
    # Calculate how much longer Anago-kun can survive starting from current_time_marker with 0 mucus.
    
    event_time = current_time_marker + V # Time when mucus reaches V
    time_since_last_sniff = event_time - last_sniff_time

    if time_since_last_sniff >= T:
        # Sniff is possible.
        # Sniff at event_time. Level V-1. Last sniff time updates to event_time.
        # Reach V again at event_time + 1.
        # At event_time + 1: Cannot sniff (1 < T), cannot blow (P=0). Failure.
        final_phase_duration = V + 1
    else:
        # Sniff is not possible. Cannot blow (P=0). Failure.
        # Failure occurs at event_time when level reaches V.
        final_phase_duration = V

    # Add the duration of the final phase to the total time survived.
    total_time += final_phase_duration

    print(total_time)

solve()
0