QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#755209 | #9552. The Chariot | ucup-team133# | TL | 0ms | 0kb | Python3 | 2.1kb | 2024-11-16 16:43:17 | 2024-11-16 16:43:17 |
answer
import sys,time
from itertools import permutations
from heapq import heappop,heappush
from collections import deque
import random
import bisect
from math import log,gcd
input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())
def solve(A,B,C,X,Y,D):
"""
全部Aで済ませる
"""
res = (D+X-1)//X * A
"""
A,Bで済ませる
"""
lower = max(1,(D+X+Y-1)//(X+Y))
upper = D//X
for k in (lower,upper):
if lower <= k <= upper:
tmp_cost = k * A + B * (D - k * X)
res = min(res,tmp_cost)
"""
(X+Y)m フルに使う
"""
k_max = D//(X+Y)
for k in (1,k_max):
if 1 <= k <= k_max:
tmp_cost = k * (A+B*Y) + C * (D-k*(X+Y))
res = min(res,tmp_cost)
"""
Xmだけ走って最後だけ全部使う
"""
k_max = (D-Y-X)//X
for k in (0,k_max):
if 0 <= k <= k_max:
tmp_cost = (k+1) * A + B*Y + C * (D-k*X-X-Y)
res = min(res,tmp_cost)
return res
def brute(A,B,C,X,Y,D):
K_max = (D+X-1)//X
f = [0] * (D+1)
for x in range(1,D+1):
if x <= X:
f[x] = A
elif x <= X+Y:
f[x] = f[x-1] + B
else:
f[x] = f[x-1] + C
res_cost = [10**100] * (D+1)
res_cost[0] = 0
for _ in range(K_max):
nxt = [10**100] * (D+1)
for i in range(D+1):
for j in range(D+1):
if i+j <= D:
nxt[i+j] = min(nxt[i+j],res_cost[i]+f[j])
res_cost = nxt
return res_cost[D]
while False:
A,B,C,X,Y,D = [random.randint(1,100) for i in range(6)]
#A,B,C,X,Y,D = 8,10,3,8,2,5
exp = brute(A,B,C,X,Y,D)
res = solve(A,B,C,X,Y,D)
if exp!=res:
print("WA")
print(A,B,C,X,Y,D)
print(exp,res)
exit()
else:
print("AC",exp)
for _ in range(int(input())):
A,B,C,X,Y,D = mi()
print(brute(A,B,C,X,Y,D))
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
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