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

19722번 - Unique Solution 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB99252334.328%

문제

Professor is preparing a task for higher math students.

The task is the following. The students are given $n$ integers $x_1, x_2, \ldots, x_n,ドル and an integer $m$ (1ドル \le m < 2^n$).

The student must choose $n$ integers $a_1, a_2, \ldots, a_n,ドル each either $-1,ドル 0ドル,ドル or 1ドル,ドル at least one non-zero value be chosen. The chosen integers must satisfy the condition that $a_1x_1+a_2x_2+\ldots+a_nx_n$ is divisible by $m$.

The professor has decided that the answer to the task should be some given array of integers $a_1, a_2, \ldots, a_n$ ($-1 \le a_i \le 1,ドル at least one of them is not equal to 0ドル$). To make his job of checking students' solutions easier, he wants to choose such integers $x_1, x_2, \ldots, x_n$ and an integer $m,ドル that his array $a_1, a_2, \ldots, a_n$ is the only possible solution. Unfortunately it is not possible, because the array $-a_1, -a_2, \ldots, -a_n$ is always a solution too.

So the professor relaxes his requirements, and wants the only two solutions be $a_1, a_2, \ldots, a_n$ and $-a_1, -a_2, \ldots, -a_n$.

Help him choose integers $x_1, x_2, \ldots, x_n$ and an integer $m$.

입력

The first line of input contains an integer $n$ (1ドル \leq n \leq 30$).

The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-1 \leq a_i \leq 1$). At least one of $a_i$ is not equal to 0ドル$.

출력

The first line of output must contain and integer $m$ (1ドル \le m < 2^n$).

The next line must contain $n$ integers $x_1, x_2, \ldots, x_n$ ($-2^{30} < x_i < 2^{30}$).

If there are several possible answers, output any of them.

It is known that the answer always exists.

제한

예제 입력 1

2
1 -1

예제 출력 1

3
1 4

힌트

In the given example the students must choose $a_1$ and $a_2$ so that $a_1 + 4a_2$ is divisible by 3ドル$. There are two possible solutions:

  • $a_1 = 1,ドル $a_1 = -1$ ($a_1 + 4a_2 = 1 - 4 = -3,ドル divisible by 3ドル$) and
  • $a_1 = -1,ドル $a_2 = 1$ ($a_1 + 4a_2 = -1 + 4 = 3,ドル divisible by 3ドル$).

Professor's requirements are met.

출처

Olympiad > Russian Olympiad in Informatics > Russia High School Programming Contest > Russia High School Programming Contest 2019 E번

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

출처

대학교 대회

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

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