Hi all,
I've bee trying to solve the problem ARMY: spoj.pl/problems/ARMY/2
but I can't beat the time limit. Here is my code.
#!/usr/bin/python
import sys
import psyco
def main():
file = sys.stdin
ip = file.read()
ip = ip.split()
t = int(ip[0])
ip = ip[1:]
while t:
t -= 1
ng = int(ip[0])
nm = int(ip[1])
ng_list = []
nm_list = []
for i in ip[2:2 + ng]:
ng_list.append(int(i))
for i in ip[2 + ng:2 + ng + nm]:
nm_list.append(int(i))
ip = ip[2 + ng + nm:]
ng_list.sort()
nm_list.sort()
i = 0
j = 0
while i < ng and j < nm:
if ng_list[i] < nm_list[j]:
i += 1
else:
j += 1
if i < ng:
print 'Godzilla'
else:
print 'MechaGodzilla'
if __name__ == '__main__':
main()
I've solved the problem using the same algorithm using C++ before. I'm not sure if I have to use a better algorithm or my python implementation is slow. Any help/hint is appreciated.
created
last reply
- 3
replies
- 304
views
- 3
users
- 1
link