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

29636번 - Enigmatic Number 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB707516.129%

문제

John is a junior researcher in the Research Institute for the Meaning of Life. Recently, he discovered that the decimal number $N$ contains knowledge that can shed light on some of the issues of the human life. However, John is selfish person and he does not want to share his discovery. So he decided to remember this number and to eat all records associated with it.

Unfortunately, John is a bit distracted and forgetful, so he decided to use the following way to remember the number $N$. There is a set of $K$ numbers connected with the life of John, which he remembers very well, even better than the date of his birth. All these numbers contain no more than three digits.

John is trying to represent the number $N$ as a concatenation of numbers from this set (e.g., a concatenation of the numbers 1ドル$ and 2ドル$ can give 12ドル$ or 21ドル$ depending on the order). No number can be used twice, on the other hand it is not obligatory to use all numbers. John wants to find (for easier remembering) a representation, containing as few numbers as possible.

Write a program that will find such a representation.

입력

First line of the input file contains an integer number $N$ (1ドル \le N < 10^{45}$). Second line contains an integer number $K$ --- size of the memorable numbers set (1ドル \le K \le 1000$). Third line contains $K$ memorable numbers (0ドル \le a_i < 1000$). All numbers in the set are different and do not have extra leading zeroes.

출력

In the first line of the output file output an integer number $M$ --- size of the desired partition. In the following $M$ lines output the numbers forming the partition (in the order in which they need to be concatenated to obtain the number $N$).

If there exist multiple partitions satisfying the criteria described, output any of them. It is guaranteed that at least one desired partition of $N$ exists.

제한

예제 입력 1

123
4
1 3 12 23

예제 출력 1

2
12
3

예제 입력 2

123
4
1 2 3 123

예제 출력 2

1
123

힌트

출처

Olympiad > Russian Olympiad in Informatics > Internet Olympiads in Informatics > 2009-2010 Season > February 13, 2010 C번

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

출처

대학교 대회

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

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