結果
問題 |
No.518 ローマ数字の和
|
ユーザー |
![]() |
提出日時 | 2025-07-07 14:52:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,137 bytes |
コンパイル時間 | 391 ms |
コンパイル使用メモリ | 81,932 KB |
実行使用メモリ | 54,204 KB |
最終ジャッジ日時 | 2025-07-07 14:52:39 |
合計ジャッジ時間 | 2,560 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
X1 = [(),(0,),(0,0),(0,0,0),(0,1),(1,),(1,0),(1,0,0),(1,0,0,0),(0,2)] X2 = [("I","V","X"),("X","L","C"),("C","D","M"),("M",)] def decode(S): i = 0 ret = 0 st = 0 N = len(S) j = N-1 while 0 <= j: s = S[j] if st == 0: if s == X2[i][0]: ret += 10 ** i j -= 1 elif s == X2[i][1]: st = 1 ret += 5 * 10 ** i j -= 1 elif s == X2[i][2]: st = 1 ret += 10 ** (i + 1) j -= 1 else: i += 1 elif st == 1: if s == X2[i][0]: ret -= 10 ** i j -= 1 st = 0 i += 1 return ret def encode(x): ret = [] if x > 3999: print("ERROR") exit() i = 0 while x > 0: a = x % 10 tmp = "" for j in X1[a]: tmp += X2[i][j] ret.append(tmp) i += 1 x //= 10 return "".join(ret[::-1]) N = int(input()) R = input().split() print(encode(sum([decode(r) for r in R])))