fork(2) download
  1. import Data.List
  2.  
  3. main = fmap lines getContents >>= \[predmeti,birki] -> let
  4. (predmeti',birki') = unzip $ head $ soljushen (words predmeti) birki
  5. in mapM_ (putStrLn . unwords) [predmeti',birki']
  6.  
  7. soljushen [] [] = [[]]
  8. soljushen predmeti birki = [(birka,predmet):solushn |
  9. (levo,predmet:pravo) <- zip (inits predmeti) (tails predmeti),
  10. let birka = zipWith const birki predmet,
  11. sort predmet == sort birka,
  12. solushn <- soljushen (levo++pravo) (birki\\birka)]
Time limit exceeded #stdin #stdout 5s 7276KB
stdin
abab ab ab ab ab ab ab ab ab ab ab ab
abababababababababababaabb
stdout
Standard output is empty