結果
問題 | No.518 ローマ数字の和 |
ユーザー |
![]() |
提出日時 | 2017-05-28 21:54:21 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 34 ms / 2,000 ms |
コード長 | 851 bytes |
コンパイル時間 | 82 ms |
コンパイル使用メモリ | 12,800 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-09-21 15:24:15 |
合計ジャッジ時間 | 1,630 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#!/usr/bin/env python3 MAX_NUM = 3999 ROMAN_VALS = (('I', 1), ('IV', 4), ('V', 5), ('IX', 9), ('X', 10), ('XL', 40), ('L', 50), ('XC', 90), ('C', 100), ('CD', 400), ('D', 500), ('CM', 900), ('M', 1000))[::-1] def roman2arabic(roman): res = 0 for s, v in ROMAN_VALS: while roman.startswith(s): res += v roman = roman[len(s):] return res def arabic2roman(x): res = "" for s, v in ROMAN_VALS: d, x = divmod(x, v) res += d * s return res def sum_romans(romans): s = sum(roman2arabic(roman) for roman in romans) if s > MAX_NUM: return None else: return arabic2roman(s) def main(): _ = input() res = sum_romans(input().split()) print("ERROR" if res is None else res) if __name__ == '__main__': main()