fork download
  1. import collections
  2.  
  3.  
  4. def yoba(c, s, path=()):
  5.  
  6. if not s:
  7.  
  8. yield path
  9.  
  10. if isinstance(c, str):
  11.  
  12. c = collections.Counter(str.split(c))
  13.  
  14. for word in sorted(c, key=len, reverse=True):
  15.  
  16. head, tail = s[:len(word)], s[len(word):]
  17. if sorted(word) == sorted(head):
  18.  
  19. for res in yoba(c - collections.Counter(**{word: 1}), tail, path + ((word, head),)):
  20.  
  21. yield res
  22.  
  23.  
  24. a, b = input(), input()
  25. print("\n".join(map(" ".join, zip(*next(yoba(a, b))))))
  26.  
Time limit exceeded #stdin #stdout 5s 9440KB
stdin
abab abab abab abab abab abab abab abab abab abab abab abab abab abab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab ab
ababababababababababababababababababababababababababababaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb
stdout
Standard output is empty