結果

問題 No.2299 Antitypoglycemia
ユーザー mtwtkmanmtwtkman
提出日時 2023-05-14 21:07:49
言語 Haskell
(9.8.2)
結果
AC  
実行時間 62 ms / 2,000 ms
コード長 734 bytes
コンパイル時間 2,693 ms
コンパイル使用メモリ 163,812 KB
実行使用メモリ 18,776 KB
最終ジャッジ日時 2023-08-20 07:13:04
合計ジャッジ時間 4,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,092 KB
testcase_01 AC 3 ms
7,192 KB
testcase_02 AC 2 ms
7,312 KB
testcase_03 AC 42 ms
16,692 KB
testcase_04 AC 42 ms
16,892 KB
testcase_05 AC 32 ms
14,340 KB
testcase_06 AC 43 ms
16,856 KB
testcase_07 AC 13 ms
12,604 KB
testcase_08 AC 42 ms
15,936 KB
testcase_09 AC 42 ms
16,396 KB
testcase_10 AC 22 ms
13,040 KB
testcase_11 AC 23 ms
13,540 KB
testcase_12 AC 53 ms
16,680 KB
testcase_13 AC 62 ms
17,352 KB
testcase_14 AC 12 ms
10,344 KB
testcase_15 AC 7 ms
9,956 KB
testcase_16 AC 22 ms
14,132 KB
testcase_17 AC 22 ms
13,268 KB
testcase_18 AC 52 ms
18,364 KB
testcase_19 AC 52 ms
18,392 KB
testcase_20 AC 62 ms
18,676 KB
testcase_21 AC 62 ms
18,776 KB
testcase_22 AC 52 ms
18,336 KB
testcase_23 AC 3 ms
7,032 KB
testcase_24 AC 3 ms
7,104 KB
testcase_25 AC 2 ms
6,992 KB
testcase_26 AC 3 ms
7,036 KB
testcase_27 AC 2 ms
7,052 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

m = 998244353

fac :: Integer -> Integer
-- fac 0 = 1
-- fac n = (fac (n - 1) * n) `mod` m

fac n = foldr (\x acc -> (acc * x) `mod` m) 1 [1..n]

solve :: Integer -> Integer -> Integer -> Integer
solve n a b =
  let r = (fac n + ((m - 2) * fac (n - 1)) `mod` m) `mod` m
   in if a /= b then (r + fac (n - 2)) `mod` m else r

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