Logo
(追記) (追記ここまで)

23775번 - IXth Problem 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB278829.630%

문제

Emily recently learned about the Roman Empire and its civilization at school. One aspect that was especially fascinating to her is the number system that they used, the Roman numerals. The Roman number system uses seven distinct digits, each representing a different value and denoted by a letter, where I is 1ドル,ドル V is 5ドル,ドル X is 10ドル,ドル L is 50ドル,ドル C is 100ドル,ドル D is 500ドル$ and M is 1ドル,000円$. Multiples of 1ドル,ドル 10ドル,ドル 100ドル$ and 1ドル,000円$ are then written according to the following table:

$\times$ 1ドル$ 2ドル$ 3ドル$ 4ドル$ 5ドル$ 6ドル$ 7ドル$ 8ドル$ 9ドル$
1ドル$ I II III IV V VI VII VIII IX
10ドル$ X XX XXX XL L LX LXX LXXX XC
100ドル$ C CC CCC CD D DC DCC DCCC CM
1ドル,000円$ M MM MMM

Most of the numerals in this table are formed additively, i.e. by summing the values of the digits. For example, LXX is 50ドル+10+10=70$. Columns 4ドル$ and 9ドル,ドル however, use so-called subtractive notation, where IV is read as 5ドル-1,ドル IX is read as 10ドル-1,ドル and so on.

Each number from 1ドル$ to 3ドル,999円$ is written as a combination of numerals from the table, using at most one numeral from each row and going from bottom to top. For instance, 2ドル,021円$ is MMXXI and 594ドル$ is DXCIV. Note that in this number system it is not possible to write numbers greater than 3ドル,999円$ and also that subtractive notation can only be used in the six cases above (e.g. IC is not considered a valid Roman numeral).

Emily found a bunch of old Scrabble sets in her attic. She threw out all the tiles with letters other than the Roman digits and started forming Roman numerals from the remaining tiles. It is easy to form valid numerals from the tiles by using just one tile per numeral, but what is the minimal number of numerals that can be formed while still using all the available tiles?

입력

The input consists of:

  • One line with seven integers $m,ドル $d,ドル $c,ドル $\ell,ドル $x,ドル $v$ and $i$ (0ドル \le m,d,c,\ell,x,v,i \le 10^{18}$), which respectively are the number of M, D, C, L, X, V and I tiles that must be used.

There is at least one tile, that is $m+d+c+\ell+x+v+i \ge 1$.

출력

Output an integer $n,ドル the minimal possible number of Roman numerals that can be formed while using all of the tiles in the input. Then output an optimal solution in the following format.

  • An integer $k,ドル the number of distinct Roman numerals used in this solution.
  • $k$ pairs of a Roman numeral and a positive integer indicating how often this numeral is used in this solution.

The solution must consist of exactly $n$ numerals in total and must use exactly the specified number of each letter. The $k$ Roman numerals in the solution must be distinct. You do not need to minimize $k$. If there is more than one optimal solution, any one of them will be accepted.

제한

예제 입력 1

4 1 7 1 3 1 3

예제 출력 1

2
2
MMDCCCLXX 1
MMCCCXCVIII 1

예제 입력 2

0 0 0 300 2000 1000 2100

예제 출력 2

1000
2
XXVIII 700
LXXV 300

힌트

출처

ICPC > Regionals > Europe > Northwestern European Regional Contest > NWERC 2021 I번

  • 문제를 만든 사람: Antti Laaksonen, Paul Wild
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /