結果

問題 No.518 ローマ数字の和
ユーザー rpy3cpprpy3cpp
提出日時 2017-05-28 22:23:26
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,209 bytes
コンパイル時間 217 ms
コンパイル使用メモリ 12,004 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2023-10-21 14:20:20
合計ジャッジ時間 1,654 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
10,240 KB
testcase_01 AC 29 ms
10,240 KB
testcase_02 AC 30 ms
10,240 KB
testcase_03 AC 30 ms
10,240 KB
testcase_04 AC 30 ms
10,240 KB
testcase_05 AC 29 ms
10,240 KB
testcase_06 AC 29 ms
10,240 KB
testcase_07 AC 29 ms
10,240 KB
testcase_08 AC 29 ms
10,240 KB
testcase_09 AC 30 ms
10,240 KB
testcase_10 AC 29 ms
10,240 KB
testcase_11 AC 29 ms
10,240 KB
testcase_12 AC 29 ms
10,240 KB
testcase_13 AC 30 ms
10,240 KB
testcase_14 AC 30 ms
10,240 KB
testcase_15 AC 30 ms
10,240 KB
testcase_16 AC 29 ms
10,240 KB
testcase_17 AC 29 ms
10,240 KB
testcase_18 AC 29 ms
10,240 KB
testcase_19 AC 30 ms
10,240 KB
testcase_20 AC 30 ms
10,240 KB
testcase_21 AC 29 ms
10,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def r2a(r):
    c2v = {'I':1, 'V':5, 'X':10, 'L':50, 'C':100, 'D':500, 'M':1000}
    r = r.replace('IV', 'IIII')
    r = r.replace('IX', 'VIIII')
    r = r.replace('XL', 'XXXX')
    r = r.replace('XC', 'LXXXX')
    r = r.replace('CD', 'CCCC')
    r = r.replace('CM', 'DCCCC')
    return sum(c2v[c] for c in r)

def a2r(a):
    if a > 3999:
        return "ERROR"
    r = []
    while (a >= 1000):
        r.append('M')
        a -= 1000
    while (a >= 500):
        r.append('D')
        a -= 500
    while (a >= 100):
        r.append('C')
        a -= 100
    while (a >= 50):
        r.append('L')
        a -= 50
    while (a >= 10):
        r.append('X')
        a -= 10
    while (a >= 5):
        r.append('V')
        a -= 5
    while (a >= 1):
        r.append('I')
        a -= 1
    r = ''.join(r)
    r = r.replace('DCCCC', 'CM')
    r = r.replace('CCCC', 'CD')
    r = r.replace('LXXXX', 'XC')
    r = r.replace('XXXX', 'XL')
    r = r.replace('VIIII', 'IX')
    r = r.replace('IIII', 'IV')
    return r

def solve(N, Rs):
    a = sum(map(r2a, Rs))
    return a2r(a)

def read_data():
    N = int(input())
    Rs = list(input().split())
    return N, Rs

N, Rs = read_data()
print(solve(N, Rs))
0