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

16093번 - The Total is Right 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB101321531.915%

문제

The total is right is a popular TV game that has been broadcast in many countries. The goal of the game is to reach a chosen number N using the four arithmetic operations (+, −, ×, ÷) and six given integer numbers mi for 1 ≤ i ≤ 6. All the intermediate numbers must be positive and any division must be exact (for example, it is not possible to divide 5 by 2). The input numbers mi as well as all intermediate numbers can be used at most once, but you are not required to use all input numbers.

For instance, suppose N = 888 and m1 = 100, m2 = 6, m3 = 75, m4 = 3, m5 = 1, and m6 = 6. We can then obtain N = 888 by computing

  • 75 − 1 = 74 (using m3/m5)
  • 6 + 6 = 12 (using m2/m6)

and finally

  • 74 × 12 = 888. (using m3/m5 and m2/m6 respectively)

Hence, in that example, the total is right!

입력

The input file consists of multiple test cases. The first line of the input file consists of a single integer indicating the number of test cases. Each test case follows, and consists of one single line that consists of seven integers N, m1, m2, m3, m4, m5, and m6, each separated by a single space. The integer 101 ≤ N ≤ 999 is the number that must be reached, and the integers mi are the numbers that can be used to reach N: for each 1 ≤ i ≤ 6, we have mi ∈ {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 25, 50, 75, 100}.

출력

For each test case in the input, your program should print one line consisting of the string The total is right (followed by a newline) or of the string Impossible (followed by a newline), depending on whether or not it is possible to obtain exactly N using some or all of the numbers mi for 1 ≤ i ≤ 6 according to the rules of the game. There should not be any blank lines in your output.

제한

예제 입력 1

2
888 100 6 75 3 1 6
449 2 6 100 10 2 8

예제 출력 1

The total is right
Impossible

힌트

출처

ICPC > Regionals > Europe > Southwestern European Regional Contest > Télécom ParisTech Internal Selection > Concours interne de programmation Télécom ParisTech 2018 G번

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

출처

대학교 대회

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

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