結果

問題 No.143 豆
ユーザー mtwtkmanmtwtkman
提出日時 2023-05-15 18:44:28
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 1,000 ms
コード長 679 bytes
コンパイル時間 13,827 ms
コンパイル使用メモリ 164,588 KB
実行使用メモリ 7,816 KB
最終ジャッジ日時 2023-08-20 19:23:33
合計ジャッジ時間 11,586 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,072 KB
testcase_01 AC 3 ms
7,556 KB
testcase_02 AC 3 ms
7,352 KB
testcase_03 AC 3 ms
7,368 KB
testcase_04 AC 3 ms
7,468 KB
testcase_05 AC 3 ms
7,576 KB
testcase_06 AC 3 ms
7,692 KB
testcase_07 AC 4 ms
7,712 KB
testcase_08 AC 3 ms
7,704 KB
testcase_09 AC 4 ms
7,720 KB
testcase_10 AC 3 ms
7,688 KB
testcase_11 AC 3 ms
7,276 KB
testcase_12 AC 3 ms
7,552 KB
testcase_13 AC 3 ms
7,768 KB
testcase_14 AC 3 ms
7,764 KB
testcase_15 AC 4 ms
7,816 KB
testcase_16 AC 3 ms
7,128 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 #

split :: String -> [String]
split = go ("", [])
  where
    go :: (String, [String]) -> String -> [String]
    go (a, acc) "" = acc <> [a]
    go (a, acc) (' ' : xs) = go ("", acc <> [a]) xs
    go (a, acc) (x : xs) = go (a <> [x], acc) xs

prompt :: IO [String]
prompt = do split <$> getLine


solve :: Int -> Int -> Int -> [Int] -> Int
solve k n f vs = let totalAge = sum vs
                     totalBeans = k * n
                  in if totalBeans < totalAge then -1 else totalBeans - totalAge

main :: IO ()
main = do
  input1 <- prompt
  input2 <- prompt
  let [k, n, f] = map read [head input1, input1 !! 1, input1 !! 2]
      vs = map read input2
  print $ solve k n f vs
0