CF1725H.Hot Black Hot White
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
One day, you are accepted as being Dr. Chanek's assistant. The first task given by Dr. Chanek to you is to take care and store his magical stones.
Dr. Chanek has N magical stones with N being an even number. Those magical stones are numbered from 1 to N . Magical stone i has a strength of Ai . A magical stone can be painted with two colours, namely the colour black or the colour white. You are tasked to paint the magical stones with the colour black or white and store the magical stones into a magic box with a magic coefficient Z ( 0≤Z≤2 ). The painting of the magical stones must be done in a way such that there are 2N black magical stones and 2N white magical stones.
Define concat(x,y) for two integers x and y as the result of concatenating the digits of x to the left of y in their decimal representation without changing the order. As an example, concat(10,24) will result in 1024 .
For a magic box with a magic coefficient Z , magical stone i will react with magical stone j if the colours of both stones are different and concat(Ai,Aj)×concat(Aj,Ai)+Ai×Aj≡Zmod3 . A magical stone that is reacting will be very hot and dangerous. Because of that, you must colour the magical stones and determine the magic coefficient Z of the magic box in a way such that there is no magical stone that reacts, or report if it is impossible.
输入格式
The first line contains a single even integer N ( 2≤N≤105 ) — the number of magical stones Dr. Chanek has.
The second line contains N integer A1,A2,…,AN ( 1≤Ai≤109 ) — the strengths of all magical stones.
输出格式
If it is not possible to satisfy the condition of the problem, output −1 .
Otherwise, output two lines. The first line contains an integer Z denoting the magic coefficient of the magic box. The second line contains a string S of length N . Si is 0 if magical stone i is coloured black or 1 if magical stone i is coloured white. If there are more than one possibilities of colouring and choosing the magic coefficient Z , output any of them.
输入输出样例
输入#1
4 4 10 9 14
输出#1
0 1001
说明/提示
By giving the above colouring, it can be seen that:
- i=1,j=2⟶concat(4,10)×concat(10,4)+10×4=410×104+40=42680≡2mod3
- i=1,j=3⟶concat(4,9)×concat(9,4)+4×9=49×94+36=4642≡1mod3
- i=4,j=2⟶concat(14,10)×concat(10,14)+10×14=1410×1014+140=1429880≡2mod3
- i=4,j=3⟶concat(14,9)×concat(9,14)+14×9=149×914+126=136312≡1mod3
Because of that, by choosing Z=0 , it can be guaranteed that there is no magical stone that reacts.