QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#753794#9552. The Chariotucup-team087#WA 15ms11200kbPython31.8kb2024-11-16 13:38:302024-11-16 13:38:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-16 13:38:40]
  • 评测
  • 测评结果:WA
  • 用时:15ms
  • 内存:11200kb
  • [2024-11-16 13:38:30]
  • 提交

answer

import sys
from random import randint
sys.set_int_max_str_digits(10000)

def solve(A,B,C,X,Y,D):
    if B>=C:
        # X を超えるのはひとつ以下
        cand = []
        def f(n):
            if n <= 0:
                return
            R=D-n*X
            ANS=n*A
            if R<=0:
                cand.append(ANS)
                return
            if R<=Y:
                cand.append(ANS+B*R)
                return
            ANS+=B*Y
            R-=Y
            ANS+=C*R
            cand.append(ANS)

        f(1)
        K=D//X
        f(K)
        f(K+1)
        K=(D-Y)//X
        f(K)
        f(K+1)
        return min(cand)
    assert B<C

    cand=[]
    def f(n):
        if n <= 0:
            return
        R=D-n*X
        ANS=n*A
        if R<=0:
            cand.append(ANS)
            return
        if R<=n*Y:
            cand.append(ANS+B*R)
            return
        ANS += n*Y*B
        R-=n*Y
        ANS+=R*C
        cand.append(ANS)
        return
    f(1)
    K=D//X
    f(K)
    f(K+1)
    K=D//(X+Y)
    f(K)
    f(K+1)
    return min(cand)


def naive(A,B,C,X,Y,D):
    INF=10**18
    dp=[INF]*101
    dp[0]=0
    F=[0]*101
    for x in range(1,X+1):
        F[x]=A
    for x in range(X+1,X+Y+1):
        F[x]=F[x-1]+B
    for x in range(X+Y+1,101):
        F[x]=F[x-1]+C
    for x in range(D+1):
        for d in range(1,D-x+1):
            dp[x+d]=min(dp[x+d],dp[x]+F[d])
    return dp[D]

"""
while 1:
    A=randint(1,5)
    B=randint(1,5)
    C=randint(1,5)
    X=randint(1,5)
    Y=randint(1,5)
    D=randint(1,20)
    a=solve(A,B,C,X,Y,D)
    b=naive(A,B,C,X,Y,D)
    print(A,B,C,X,Y,D,a,b)
    assert a==b
"""


T=int(input())

for _ in range(T):
    A,B,C,X,Y,D=map(int,input().split())
    solve(A,B,C,X,Y,D)

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 15ms
memory: 11200kb

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:


result:

wrong answer 1st lines differ - expected: '160', found: ''