結果
問題 |
No.518 ローマ数字の和
|
ユーザー |
![]() |
提出日時 | 2023-02-20 00:58:30 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 788 bytes |
コンパイル時間 | 234 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 52,480 KB |
最終ジャッジ日時 | 2024-07-20 21:46:12 |
合計ジャッジ時間 | 1,722 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 16 WA * 3 |
ソースコード
def decode(s): s = s[::-1] pre = 0 cnt = 0 for i in range(len(s)): n = D[s[i]] if n >= pre: cnt += n else: cnt -= n pre = n return cnt def encode(m): lst = [] for i in range(len(S)): n = m // num[i] if n <= 3: lst.extend([S[i]] * n) else: lst.append(S[i]) lst.append(S[i - 1]) m %= num[i] return "".join(lst) N = int(input()) R = list(input().split()) num = [1, 5, 10, 50, 100, 500, 1000] S = ["I", "V", "X", "L", "C", "D", "M"] D = dict() for i in range(len(S)): D[S[i]] = num[i] R = list(map(decode, R)) M = sum(R) if M >= 4000: print("ERROR") exit() num.reverse() S.reverse() print(encode(M))