結果
問題 |
No.365 ジェンガソート
|
ユーザー |
![]() |
提出日時 | 2016-05-03 23:22:43 |
言語 | Haskell (9.10.1) |
結果 |
AC
|
実行時間 | 14 ms / 2,000 ms |
コード長 | 798 bytes |
コンパイル時間 | 2,892 ms |
コンパイル使用メモリ | 180,628 KB |
実行使用メモリ | 9,984 KB |
最終ジャッジ日時 | 2024-10-12 02:14:53 |
合計ジャッジ時間 | 4,377 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 41 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
import qualified Data.ByteString.Char8 as C import Data.Char main :: IO () main = do ss <- C.getLine let (x,xs) = nextInt ss ss2 <- C.getLine let ans = solve 0 x ss2 print ans solve :: Int -> Int -> C.ByteString -> Int solve i n ss | i == n = n | otherwise = if x == y then y - 1 else y where (x,xs) = nextInt ss y = solve (i + 1) n xs nextInt :: C.ByteString -> (Int, C.ByteString) nextInt ss | '0' <= x && x <= '9' = nextInt2 ss 0 | otherwise = nextInt $ C.tail ss where x = C.head ss nextInt2 :: C.ByteString -> Int -> (Int, C.ByteString) nextInt2 ss n | C.null ss = (n, ss) | '0' <= y && y <= '9' = nextInt2 ys (n * 10 + (digitToInt y)) | otherwise = (n, ys) where y = C.head ss ys = C.tail ss