本地验证通过了,但是提交上去一直报RE,请大佬帮忙看下
module Main where
import Control.Monad.Reader
import Control.Monad.State
import Data.Char
main :: IO ()
main = do
n <- read <$> getLine
m <- reverse <$> getLine {- for high-precision calculations, start with single digits and work backwards -}
putStrLn . flip runReader n . flip evalStateT 0 $ judge 0 m
type CarryBaseEnv = StateT Int {- carry -} (Reader Int {- base -})
addBaseN :: Char -> Char -> CarryBaseEnv Char
addBaseN ch1 ch2 = do
baseN <- ask
carry <- get
let [num1, num2] = digitToInt <$> [ch1, ch2]
(carryNext, rest) = divMod (num1 + num2 + carry) baseN
put carryNext
return . intToDigit $ rest
addBaseN' :: String -> String -> CarryBaseEnv String
addBaseN' str1 str2 = do
put 0
eachBit <- foldl (\x y -> (:) <$> y <*> x) (return mempty) $ uncurry addBaseN <$> zip str1 str2
carry <- get
return . (if carry == 1 then ('1' :) else id) . reverse $ eachBit
judge :: Int -> String -> CarryBaseEnv String
judge n str = if n < 30
then
let rStr = reverse str
in if str == rStr then return . showString "STEP=" $ show n else addBaseN' str rStr >>= (judge (n + 1))
else return "Impossible!"