結果

問題 No.518 ローマ数字の和
ユーザー sue_charosue_charo
提出日時 2017-05-28 23:47:17
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,348 bytes
コンパイル時間 338 ms
コンパイル使用メモリ 12,128 KB
実行使用メモリ 10,932 KB
最終ジャッジ日時 2023-10-21 14:46:46
合計ジャッジ時間 1,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

# coding: utf-8
import array, bisect, collections, copy, heapq, itertools, math, random, re, string, sys, time

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7


def II(): return int(input())
def ILI(): return list(map(int, input().split()))
def IAI(LINE): return [ILI() for __ in range(LINE)]
def IDI(): return {key: value for key, value in ILI()}


roman_table = [
    ("M", 1000),
    ("CM", 900),
    ("D", 500),
    ("CD", 400),
    ("C", 100),
    ("XC", 90),
    ("L", 50),
    ("XL", 40),
    ("X", 10),
    ("IX", 9),
    ("IV", 4),
    ("I", 1),
]


def roman_to_int(str):
    ret_num = 0
    for c, n in roman_table:
        while str.startswith(c):
            str = str[len(c):]
            ret_num += n
    return ret_num


def int_to_roman(num):
    ret_str = ""
    while num > 0:
        for c, n in roman_table:
            while num >= n:
                ret_str += c
                num -= n
    return ret_str


def read():
    N = II()
    R = list(map(str, input().split()))
    return (N, R)


def solve(N, R):
    num_sum = 0
    for r in R:
        num_sum += roman_to_int(r)
    
    ans = ""
    if num_sum >= 4000:
        ans = "ERROR"
    else:
        ans = int_to_roman(num_sum)
    
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()
0