fork(3) download
  1. import Data.List
  2. import Data.Function
  3.  
  4. main = fmap lines getContents >>= \[predmeti,birki] -> let
  5. (predmeti',birki') = unzip $ head $ soljushen sgruppirovaniePredmeti birki
  6. sgruppirovaniePredmeti = groupBy ((==) `on` sort) $ sortBy (compare `on` sort) $ words predmeti
  7. in mapM_ (putStrLn . unwords) [predmeti',birki']
  8.  
  9. soljushen _ [] = [[]]
  10. soljushen gruppi birki = [(birka,predmet):solushn |
  11. (levo,(predmet:gruppa):pravo) <- zip (inits gruppi) (tails gruppi),
  12. let birka = zipWith const birki predmet,
  13. sort predmet == sort birka,
  14. solushn <- soljushen (levo++gruppa:pravo) (birki\\birka)]
Time limit exceeded #stdin #stdout 5s 7324KB
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