結果

問題 No.5 数字のブロック
ユーザー alpha_virginis
提出日時 2016-05-04 13:08:49
言語 Haskell
(9.10.1)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 1,229 bytes
コンパイル時間 4,943 ms
コンパイル使用メモリ 180,944 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-11-18 08:32:56
合計ジャッジ時間 4,607 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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

ソースコード

diff #

import qualified Data.ByteString.Char8 as C
import Data.Char
import Data.Array.IO

main :: IO ()
main = do
  s1 <- C.getLine
  let (l, r1) = nextInt s1
  s2 <- C.getLine
  let (n, r2) = nextInt s2
  xs <- newArray (0, 10100) 0 :: IO(IOUArray Int Int)
  s3 <- C.getLine
  set n s3 xs
  writeArray xs 10010 1000000
  ans <- solve 0 l xs
  print ans

set :: Int -> C.ByteString-> IOUArray Int Int -> IO ()
set n ss xs
  | n == 0    = return ()
  | otherwise = set2 n ss xs

set2 :: Int ->  C.ByteString -> IOUArray Int Int -> IO ()
set2 n ss xs = do
  let (w,rs) = nextInt ss
  y <- readArray xs w
  writeArray xs w (y + 1)
  set (n - 1) rs xs
  
solve :: Int -> Int -> IOUArray Int Int -> IO Int
solve n l xs = do
  y <- readArray xs n
  if l >= y * n then do {
    t <- solve (n + 1) (l - y * n) xs;
    return $ t + y;
    }
    else return $ div l n
  
nextInt :: C.ByteString -> (Int, C.ByteString)
nextInt ss
  | isDigit x = nextInt2 0 ss
  | otherwise = nextInt $ C.tail ss
  where x = C.head ss

nextInt2 :: Int -> C.ByteString -> (Int, C.ByteString)
nextInt2 n ss
  | C.null ss = (n, ss)
  | isDigit y = nextInt2 (n * 10 + (digitToInt y)) ys
  | otherwise = (n, ys)
  where y  = C.head ss
        ys = C.tail ss
          
0