B is up to 10^9 and in your code, you have stuff like range(B + 1) I believe this is the reason you get runtime error.
Eugene Yarmash <[email protected]>于2018年8月16日周四 上午6:35写道: > My Python3 code solves the 1st test case, but gives a 'Runtime error' for > the 2nd. What may be the reason for this? > > As for the algorithm, I try to find all the ways to partition bits among > up to R cashiers. > > > from itertools import chain, combinations, combinations_with_replacement > > > class Cashier: > __slots__ = ('max_bits', 'scan_time', 'packaging_time') > > def __init__(self, M, S, P): > self.max_bits = M > self.scan_time = S > self.packaging_time = P > > > def main(): > T = int(input()) # the number of test cases > > for case in range(1, T+1): > R, B, C = map(int, input().split()) # robot shoppers, bits, > cashiers > > cashiers = [] > > for _ in range(C): > M, S, P = map(int, input().split()) # max number of bits, > scan time per bit, packaging time > cashier = Cashier(M, S, P) > cashiers.append(cashier) > > res = float('inf') > > for num_cashiers in range(1, R+1): > for sel_cashiers in combinations(cashiers, num_cashiers): > for bits_bars in combinations_with_replacement(range(B+1), > num_cashiers-1): > prev_bar = 0 > times = [] > > for cashier, bar in zip(sel_cashiers, chain(bits_bars, > (B,))): > num_bits = bar - prev_bar > prev_bar = bar > if num_bits > cashier.max_bits: > break > times.append(num_bits*cashier.scan_time + > cashier.packaging_time) > else: > time = max(times) > if time < res: > res = time > > print('Case #{}: {}'.format(case, res)) > > > main() > > -- > Regards, > Eugene > > -- > You received this message because you are subscribed to the Google Groups > "Google Code Jam" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/google-code/914b7f44-b1d9-f6bf-44f4-06e145ae09f0%40gmail.com > <https://groups.google.com/d/msgid/google-code/914b7f44-b1d9-f6bf-44f4-06e145ae09f0%40gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Google Code Jam" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/google-code/CAGDEU-JB%3DTSoGX%3D5NGPUU5kv8V6OJ7fq%3DuO0y-kkmZmSAhx1eg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
