結果

問題 No.518 ローマ数字の和
ユーザー titiatitia
提出日時 2024-01-21 01:20:07
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,165 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2024-01-21 01:20:10
合計ジャッジ時間 2,367 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

D={"I" : 1,"V" : 5,"X": 10,"L" : 50,"C" : 100,"D" : 500,"M" : 1000}

N=int(input())
A=input().split()

ANS=0

for a in A:
    ind=0

    while ind<len(a):
        if ind+1<len(a) and D[a[ind]]<D[a[ind+1]]:
            ANS+=D[a[ind+1]]-D[a[ind]]
            ind+=2
        else:
            ANS+=D[a[ind]]
            ind+=1

if ANS>=4000:
    print("ERROR")
    exit()

LS=""

while ANS:
    if ANS>=1000:
        LS+="M"
        ANS-=1000
        
    elif ANS>=900:
        LS+="CM"
        ANS-=900
        
    elif ANS>=500:
        LS+="D"
        ANS-=500
        
    elif ANS>=400:
        LS+="CD"
        ANS-=400
        
    elif ANS>=100:
        LS+="C"
        ANS-=100

    elif ANS>=90:
        LS+="XC"
        ANS-=90
        
    elif ANS>=50:
        LS+="L"
        ANS-=50
        
    elif ANS>=40:
        LS+="XL"
        ANS-=40
        
    elif ANS>=10:
        LS+="X"
        ANS-=10
 
    elif ANS>=9:
        LS+="IX"
        ANS-=9
        
    elif ANS>=5:
        LS+="V"
        ANS-=5
        
    elif ANS>=4:
        LS+="IV"
        ANS-=4
        
    elif ANS>=1:
        LS+="I"
        ANS-=1

print(LS)

    
        
0