fork download
  1. s = input()
  2. t = input()
  3.  
  4. n = len(s)
  5. m = len(t)
  6. x = [0]*(m+1)
  7. y = [0]*(m+1)
  8. z = [0]*(m+1)
  9.  
  10. for i in range(1,n+1):
  11. nx = [0]*(m+1)
  12. ny = [0]*(m+1)
  13. nz = [0]*(m+1)
  14. for j in range(1,m+1):
  15. nx[j] = max(x[j], nx[j-1])
  16. ny[j] = max(y[j], ny[j-1])
  17. nz[j] = max(z[j], nz[j-1])
  18. if s[i-1] == t[j-1]:
  19. if s[i-1] == '0':
  20. nx[j] = max(nx[j], x[j-1] + 1)
  21. nz[j] = max(nz[j],z[j-1] + 1,y[j-1] + 1)
  22. else:
  23. ny[j] = max(ny[j],y[j-1] + 1,x[j-1] + 1)
  24. x = nx
  25. y = ny
  26. z = nz
  27. #print(x,y,z)
  28. print(max(x[m], y[m], z[m]))
  29. # your code goes here
Success #stdin #stdout 0.07s 14096KB
stdin
10011010
0101010010
stdout
6