fork(8) download
  1. primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71,
  2. 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157,
  3. 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239]
  4.  
  5. bukvi = ('a'..'z').to_a + ('A'..'Z').to_a
  6. TABLICA = Hash[bukvi.zip(1..52)]
  7. CHISLA = primes.take(bukvi.size)
  8.  
  9. class String
  10. def hesh
  11. self.split('').reduce(1) { |a,b| CHISLA[TABLICA[b]] * a }
  12. end
  13. end
  14.  
  15. veshi = gets.chomp.split
  16. birki = gets.chomp
  17.  
  18. veshi.permutation.each do |x|
  19. i = 0
  20. if x.all? { |vesh| vesh.hesh == birki[i..((i += vesh.size) - 1)].hesh }
  21. krasivie_birki = ''
  22. birki = birki.split('')
  23. x.each { |s| krasivie_birki << (birki.shift(s.size).join + ' ') }
  24. puts krasivie_birki
  25. puts x.join(' ')
  26. break
  27. end
  28. end
Time limit exceeded #stdin #stdout 5s 8004KB
stdin
abab ab ab ab ab ab ab ab ab ab ab ab
abababababababababababaabb
stdout
Standard output is empty