結果

問題 No.518 ローマ数字の和
ユーザー McGregorsh
提出日時 2022-10-31 15:14:12
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 4,086 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 89,216 KB
最終ジャッジ日時 2024-07-08 04:12:55
合計ジャッジ時間 5,343 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

import sys, re
from fractions import Fraction
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque, defaultdict
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement, permutations
from bisect import bisect, bisect_left, bisect_right
from functools import reduce, lru_cache
from decimal import Decimal, getcontext, ROUND_HALF_UP
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
def get_distance(x1, y1, x2, y2):
d = sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
return d
def rotate(table):
n_fild = []
for x in zip(*table[::-1]):
n_fild.append(x)
return n_fild
sys.setrecursionlimit(10 ** 7)
INF = float('inf')
MOD = 10 ** 9 + 7
MOD2 = 998244353
######
def main():
N = int(input())
R = s_list()
score = defaultdict(int)
score['I'] = 1
score['V'] = 5
score['X'] = 10
score['L'] = 50
score['C'] = 100
score['D'] = 500
score['M'] = 1000
ans = 0
for i in range(N):
cou = 0
nums = []
for j in range(len(R[i])):
point = R[i][j]
if point == 'I':
nums.append(1)
elif point == 'V':
nums.append(5)
elif point == 'X':
nums.append(10)
elif point == 'L':
nums.append(50)
elif point == 'C':
nums.append(100)
elif point == 'D':
nums.append(500)
else:
nums.append(1000)
now = INF
for k in range(len(nums)):
if now >= nums[k]:
cou += nums[k]
else:
A = score[R[i][k]]
B = score[R[i][k-1]]
C = str(A - B)
if C[0] == '4':
cou += 3 * B
else:
cou += 8 * B
now = nums[k]
ans += cou
if ans >= 4000:
print('ERROR')
exit()
counts = []
ans = '00000' + str(ans)
ans = ans[::-1]
if ans[3] == '1':
counts.append('M')
elif ans[3] == '2':
counts.append('MM')
elif ans[3] == '3':
counts.append('MMM')
if ans[2] == '1':
counts.append('C')
elif ans[2] == '2':
counts.append('CC')
elif ans[2] == '3':
counts.append('CCC')
elif ans[2] == '4':
counts.append('CD')
elif ans[2] == '5':
counts.append('D')
elif ans[2] == '6':
counts.append('DC')
elif ans[2] == '7':
counts.append('DCC')
elif ans[2] == '8':
counts.append('DCCC')
elif ans[2] == '9':
counts.append('CM')
if ans[1] == '1':
counts.append('X')
elif ans[1] == '2':
counts.append('XX')
elif ans[1] == '3':
counts.append('XXX')
elif ans[1] == '4':
counts.append('XL')
elif ans[1] == '5':
counts.append('L')
elif ans[1] == '6':
counts.append('LX')
elif ans[1] == '7':
counts.append('LXX')
elif ans[1] == '8':
counts.append('LXXX')
elif ans[1] == '9':
counts.append('XC')
if ans[0] == '1':
counts.append('I')
elif ans[0] == '2':
counts.append('II')
elif ans[0] == '3':
counts.append('III')
elif ans[0] == '4':
counts.append('IV')
elif ans[0] == '5':
counts.append('V')
elif ans[0] == '6':
counts.append('VI')
elif ans[0] == '7':
counts.append('VII')
elif ans[0] == '8':
counts.append('VIII')
elif ans[0] == '9':
counts.append('IX')
print(''.join(counts))
if __name__ == '__main__':
main()
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0