QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#827521#9552. The ChariotLilyWhiteWA 16ms10640kbPython31.6kb2024-12-23 00:45:322024-12-23 00:45:32

Judging History

This is the latest submission verdict.

  • [2024-12-23 00:45:32]
  • Judged
  • Verdict: WA
  • Time: 16ms
  • Memory: 10640kb
  • [2024-12-23 00:45:32]
  • Submitted

answer

import sys

def minimal_travel_cost(A, B, C, X, Y, D):
    # Option1: Re-hail every X meters
    option1 = ((D + X - 1) // X) * A

    # Option2: Re-hail every (X + Y) meters
    k = D // (X + Y)
    R = D % (X + Y)

    if R == 0:
        option2 = k * (A + B * Y)
    elif R <= X:
        option2 = k * (A + B * Y) + A
    else:
        option2 = k * (A + B * Y) + A + B * (R - X)

    # Additionally, consider reducing one full segment to optimize residual
    if k > 0:
        # Reduce one full segment
        option2_reduced = (k - 1) * (A + B * Y)
        R_new = D - (k - 1) * (X + Y)
        if R_new <= X:
            option2_reduced += A
        else:
            option2_reduced += A + B * (R_new - X)
        # Take the minimum between original Option2 and reduced Option2
        option2 = min(option2, option2_reduced)

    # Option3: Take a single cab for the entire journey
    if D <= X:
        option3 = A
    elif D <= X + Y:
        option3 = A + B * (D - X)
    else:
        option3 = A + B * Y + C * (D - X - Y)

    # Return the minimal cost
    return min(option1, option2, option3)

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    T = int(data[0])
    idx = 1
    results = []
    for _ in range(T):
        A = int(data[idx])
        B = int(data[idx+1])
        C = int(data[idx+2])
        X = int(data[idx+3])
        Y = int(data[idx+4])
        D = int(data[idx+5])
        idx +=6
        cost = minimal_travel_cost(A, B, C, X, Y, D)
        results.append(str(cost))
    print('\n'.join(results))

if __name__ == "__main__":
    main()

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 16ms
memory: 10640kb

input:

5
160 27 41 3 12 3
160 27 41 3 12 4
160 27 41 3 12 99
1 999 999 1 99 999
999 999 1 1 99 9999999999999999

output:

160
187
3147
999
10000000000099799

result:

wrong answer 3rd lines differ - expected: '3226', found: '3147'