結果

問題 No.518 ローマ数字の和
ユーザー sue_charosue_charo
提出日時 2017-06-01 23:27:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 1,254 bytes
コンパイル時間 91 ms
コンパイル使用メモリ 12,148 KB
実行使用メモリ 10,872 KB
最終ジャッジ日時 2023-10-21 20:18:19
合計ジャッジ時間 1,610 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
10,872 KB
testcase_01 AC 33 ms
10,872 KB
testcase_02 AC 39 ms
10,872 KB
testcase_03 AC 37 ms
10,872 KB
testcase_04 AC 36 ms
10,872 KB
testcase_05 AC 35 ms
10,872 KB
testcase_06 AC 33 ms
10,872 KB
testcase_07 AC 35 ms
10,872 KB
testcase_08 AC 33 ms
10,872 KB
testcase_09 AC 32 ms
10,872 KB
testcase_10 AC 33 ms
10,872 KB
testcase_11 AC 35 ms
10,872 KB
testcase_12 AC 34 ms
10,872 KB
testcase_13 AC 33 ms
10,872 KB
testcase_14 AC 34 ms
10,872 KB
testcase_15 AC 34 ms
10,872 KB
testcase_16 AC 33 ms
10,872 KB
testcase_17 AC 34 ms
10,872 KB
testcase_18 AC 33 ms
10,872 KB
testcase_19 AC 32 ms
10,872 KB
testcase_20 AC 33 ms
10,872 KB
testcase_21 AC 33 ms
10,872 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),
    ("V", 5),
    ("IV", 4),
    ("I", 1),
]


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


def int_to_roman(num):
    ret_str = ""
    for c, n in roman_table:
        ret_str += c * (num // n)
        num %= n

    return ret_str


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


def solve(N, R):
    num_sum = sum(map(roman_to_int, R))
    if num_sum >= 4000:
        return "ERROR"
    else:
        return int_to_roman(num_sum)


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


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