問題一覧 > 通常問題

No.518 Sum of Roman Numerals

レベル : / AI推定難易度 : 214 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 151
作問者 : No / テスター : tatuyan_edson
お気に入りにしたユーザー ProblemId : 1276 / 自分の提出
問題文最終更新日: 2026-06-26 16:13:35
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 164 (順位表) の他の問題:

Problem Statement

There are N Roman numerals (R1,R2,R3, …… ,Rn).
What is the result (A) of adding all of these N Roman numerals?
The output must also be in Roman numerals.
However, if the number is greater than MMMCMXCIX (3999 in Arabic numerals),
output "ERROR".

Roman numerals are written by combining the following 7 letters.
I = 1, V = 5, X = 10, L = 50, C = 100, D = 500, M = 1000

In Roman numerals, repeating a letter 4 times is prohibited.
The following numbers must be written using subtractive notation.
IV = 4, IX = 9, XL = 40, XC = 90, CD = 400, CM = 900

Input

N
R1 R2 R3  ……  Rn

N is at least 2 and at most 100,
R is a Roman numeral from I to MMMCMXCIX (1 to 3999 in Arabic numerals)

Output

Output A as a string of Roman numerals.
If the number is greater than MMMCMXCIX (3999 in Arabic numerals), output "ERROR".
Print a newline at the end.

Sample

Sample 1
Input
2
II III
Output
V

2 + 3 = 5

Sample 2
Input
5
IV XXI CCCXL III MMCMVI
Output
MMMCCLXXIV

4 + 21 + 340 + 3 + 2906 = 3274

Sample 3
Input
4
M M M M
Output
ERROR

1000 + 1000 + 1000 + 1000 = 4000
The value exceeds the range, so "ERROR"

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。