結果

問題 No.518 ローマ数字の和
ユーザー Yuki_UtaaiYuki_Utaai
提出日時 2018-02-24 16:05:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 942 bytes
コンパイル時間 176 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 10,880 KB
最終ジャッジ日時 2024-04-21 14:54:12
合計ジャッジ時間 1,895 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

def roman(n,s):
    roman=["M","CM","D","CD","C","XC","L","XL","X","IX","V","IV","I"]
    arabic=[1000,900,500,400,100,90,50,40,10,9,5,4,1]
    number=[0 for i in range(n)]

    for i in range(n):
      j=0
      while j<len(s[i]):
        for k in range(len(roman)):
            if  len(roman[k])==1 and str((s[i]))[j]==roman[k]:
                number[i]+=arabic[k]
                j+=1
                break
            elif j<len(s[i])-1:
              if  len(roman[k])==2 and str((s[i]))[j]+str((s[i]))[j+1]==roman[k]:
                number[i]+=arabic[k]
                j+=2
                break
    
    ans_arabic=sum(number)
    ans_roman=""
    m=0
    if ans_arabic>=4000:
        print("ERROR")
    else:
      while ans_arabic>0:
        if ans_arabic>=arabic[m]:
            ans_roman+=roman[m]
            ans_arabic-=arabic[m]
        else:
            m+=1
    print(ans_roman)

n=int(input())
s=input().split()
roman(n,s)
0