結果

問題 No.1020 Reverse
ユーザー poapoapoapoa
提出日時 2020-07-30 12:45:54
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 924 bytes
コンパイル時間 10,309 ms
コンパイル使用メモリ 197,380 KB
実行使用メモリ 7,932 KB
最終ジャッジ日時 2023-09-16 23:40:38
合計ジャッジ時間 9,291 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,064 KB
testcase_01 AC 3 ms
6,928 KB
testcase_02 AC 2 ms
7,032 KB
testcase_03 AC 3 ms
7,068 KB
testcase_04 AC 2 ms
6,972 KB
testcase_05 AC 3 ms
6,932 KB
testcase_06 AC 2 ms
7,096 KB
testcase_07 AC 2 ms
7,456 KB
testcase_08 AC 3 ms
7,524 KB
testcase_09 AC 3 ms
7,468 KB
testcase_10 AC 3 ms
7,780 KB
testcase_11 AC 3 ms
7,840 KB
testcase_12 AC 3 ms
7,648 KB
testcase_13 AC 4 ms
7,632 KB
testcase_14 AC 3 ms
7,824 KB
testcase_15 AC 3 ms
7,860 KB
testcase_16 AC 3 ms
7,932 KB
testcase_17 AC 3 ms
7,716 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import qualified Control.Arrow         as Arrow
import qualified Control.Monad         as Monad
import qualified Data.Char             as Char
import qualified Data.List             as List
import qualified Data.ByteString.Char8 as BSC8
import qualified Data.Vector.Unboxed   as VU
import qualified Data.Ord              as Ord

getI :: BSC8.ByteString -> Maybe (Int, BSC8.ByteString)
getI = fmap (Arrow.second BSC8.tail) . BSC8.readInt
getAB :: IO (Int, Int)
getAB = (\vec -> (vec VU.! 0, vec VU.! 1)) . VU.unfoldrN 2 getI <$> BSC8.getLine

main :: IO ()
main = do
  (n, k) <- getAB
  s      <- BSC8.getLine
  if even (n - k)
    then solve' n k s
    else solve'' n k s

solve', solve'' :: Int -> Int -> BSC8.ByteString -> IO ()
solve' n k s
  = BSC8.putStrLn $ BSC8.append (BSC8.drop (k - 1) s) (BSC8.reverse $ BSC8.take (k - 1) s)
solve'' n k s
  = BSC8.putStrLn $ BSC8.append (BSC8.drop (k - 1) s) (BSC8.take (k - 1) s)
0