Haskell超时怎么解决

并不知道如何提高运行效率……

cheng [] = 1
cheng (x:xs) = x * cheng xs
solve x = do
    if x/=0
        then do
            print . cheng . map read . words =<< getLine
            solve $ x-1
        else return ()
main = do
    l <- getLine
    let n = read l
    solve n

2 条评论

  • @ 2017-11-18 16:03:26

    接着改,仍然t

    solve :: [Integer] -> IO()
    solve []      = return ()
    solve (a:b:c) = do
      print ( a * b )
      solve c
    main :: IO()
    main = solve . tail . map read . words =<< getContents
    
  • @ 2017-11-18 16:00:56

    好好学了一点Haskell之后再次写代码依然超时……

    solve :: [Integer] -> [Integer]
    solve []      = []
    solve (a:b:c) = ( a * b ) : solve c
    main :: IO()
    main = mapM_ print . solve . tail . map read . words =<< getContents
    
  • 1

信息

ID
2000
难度
8
分类
高精度 点击显示
标签
(无)
递交数
1173
已通过
102
通过率
9%
被复制
8
上传者