Today, I participated in codeforces round 162, and I made the mistakes using Python in solving problem C/D,
for example, Problem D <good sequence> is definitely a Dynamic Programming problem, and I code in Python very quickly.
It passed tests during the contest and 'accepted' shown, I thought that was it, but apparently not, after contests, harder tests were added and the Python solution got TL on Test 21..
Code: Select all
#!/usr/bin/env python
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
n = int(raw_input())
seq = map(int, raw_input().split())
f = len(seq) * [1]
for i in xrange(len(seq)):
for j in xrange(i):
if seq[j] < seq[i] and gcd(seq[j], seq[i]) > 1 and f[j] >= f[i]:
f[i] = f[j] + 1
print max(f)
I will rewrite this in C++ and see how it goes...
next time, i will not use Python to solve the difficult problems.