結果
問題 | No.518 ローマ数字の和 |
ユーザー |
|
提出日時 | 2017-05-28 21:45:59 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 31 ms / 2,000 ms |
コード長 | 704 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 12,544 KB |
実行使用メモリ | 10,752 KB |
最終ジャッジ日時 | 2024-09-21 15:21:59 |
合計ジャッジ時間 | 1,506 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#!/usr/bin/env python3roman_table = [('M', 1000),('CM', 900),('D', 500),('CD', 400),('C', 100),('XC', 90),('L', 50),('XL', 40),('X', 10),('IX', 9),('V', 5),('IV', 4),('I', 1),]def roman_to_int(s):n = 0for c, e in roman_table:while s.startswith(c):s = s[len(c) :]n += eassert not sreturn ndef int_to_roman(n):s = ''for c, e in roman_table:s += c * (n // e)n %= eassert not nreturn s_ = int(input())rs = input().split()acc = sum(map(roman_to_int, rs))if acc >= 4000:result = 'ERROR'else:result = int_to_roman(acc)print(result)