結果
問題 | No.518 ローマ数字の和 |
ユーザー | aimy |
提出日時 | 2017-05-29 22:37:21 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,089 bytes |
コンパイル時間 | 3,210 ms |
コンパイル使用メモリ | 173,312 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-09-21 18:12:43 |
合計ジャッジ時間 | 4,063 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,944 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,940 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,944 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,944 KB |
testcase_14 | AC | 1 ms
6,944 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,940 KB |
testcase_17 | AC | 2 ms
6,940 KB |
testcase_18 | AC | 2 ms
6,944 KB |
testcase_19 | AC | 2 ms
6,944 KB |
testcase_20 | AC | 2 ms
6,940 KB |
testcase_21 | AC | 1 ms
6,944 KB |
コンパイルメッセージ
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 Data.Char main = do getLine rs <- words <$> getLine putStrLn $ maybe "ERROR" id $ roman $ sum $ map arabic rs roman n | n > 3999 = Nothing | otherwise = Just $ concat $ zipWith readArabic [1000,100,10,1] (digits n) where digits = reverse . take 4 . reverse . ([0,0,0] ++) . map digitToInt . show readArabic 1000 d | d == 0 = "" | otherwise = replicate d 'M' readArabic 100 d | d == 0 = "" | d <= 3 = replicate d 'C' | d == 4 = "CD" | d == 5 = "D" | d <= 8 = 'D' : replicate (d-5) 'C' | d == 9 = "CM" readArabic 10 d | d == 0 = "" | d <= 3 = replicate d 'X' | d == 4 = "XL" | d == 5 = "L" | d <= 8 = 'L' : replicate (d-5) 'X' | d == 9 = "XC" readArabic 1 d | d == 0 = "" | d <= 3 = replicate d 'I' | d == 4 = "IV" | d == 5 = "V" | d <= 8 = 'V' : replicate (d-5) 'I' | d == 9 = "IX" arabic = sum . count . map readRoman where readRoman r = case r of {'I'->1; 'V'->5; 'X'->10; 'L'->50; 'C'->100; 'D'->500; 'M'->1000} count (x:y:xys) = if x<y then y-x : count xys else x : count (y:xys) count xs = xs