Hi Xiongqi,
I am getting a TLE when I tried to implement as per the analysis. Where am
I going wrong? Appreciate your help.
def solve(N, P, R):
torn = set(P)
store = []
for i in range(1, N + 1):
ctr, fac = 0, 1
while i * fac <= N:
if i * fac not in torn:
ctr += 1
fac += 1
store.append(ctr)
return sum(map(lambda x: store[x - 1], R))
if __name__ == '__main__':
T = int(input())
for i in range(T):
N, M, Q = map(int, input().split(' '))
P = list(map(int, input().split(' ')))
R = list(map(int, input().split(' ')))
print('Case #{}:'.format(i + 1), solve(N, P, R))
On Wednesday, November 6, 2019 at 8:52:16 AM UTC+8, Xiongqi ZHANG wrote:
>
> Your code looks good to me, except it is too slow to even pass the visible
> test. (getting TLE verdict instead of RE)
> It might be the case that you submitted the code with python2?
>
> I slightly improved your code using the approach suggested by analysis and
> passed both visible and hidden test.
> Check out the code below
>
>
> *t = int(input())*
> *for test in range(1, t + 1):*
> * n, m, q = map(int, input().split())*
>
> * p = set([int(e) for e in input().split()])*
> * r = [int(e) for e in input().split()]*
>
> * tmp = [sum([1 for page in range(i, n + 1, i) if page not in p]) for i
> in range(1, n + 1)]*
>
> * result = sum([tmp[reader - 1] for reader in r])*
>
> * print("Case #{}: {}".format(test, result))*
>
>
>
> Hi,
>> I'm new to doing Google Kickstart challenges and I tried doing the first
>> on the latest problem set (Book Reading). I did it in Python and the code
>> outputs the correct answer on my local machine, however it throws a RE when
>> I try to submit my answer.
>>
>> Here is the code:
>>
>> t = int(input())
>> for test in range(1, t + 1):
>> n, m, q = map(int, input().split())
>>
>> p = [int(e) for e in input().split()]
>> r = [int(e) for e in input().split()]
>>
>> result = 0
>> for reader in range(q):
>> result += sum([1 for page in range(1, n + 1) if page % r[reader] == 0
>> and page not in p])
>>
>> print("Case #{}: {}".format(test, result))
>>
>> Thanks for your help.
>>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/google-code/4bf8dff7-1915-4de3-9c50-fc44460ff2d2%40googlegroups.com.