5330: ABC164——Task F:I hate Matrix Construction
[Creator : ]
Description
Given are an integer NN and arrays SS, TT, UU, and VV, each of length NN. Construct an N×NN×N matrix aa that satisfy the following conditions:
- ai,jai,j is an integer.
- 0≤ai,j<2640≤ai,j<264.
- If Si=0Si=0, the bitwise AND of the elements in the ii-th row is UiUi.
- If Si=1Si=1, the bitwise OR of the elements in the ii-th row is UiUi.
- If Ti=0Ti=0, the bitwise AND of the elements in the ii-th column is ViVi.
- If Ti=1Ti=1, the bitwise OR of the elements in the ii-th column is ViVi.
However, there may be cases where no matrix satisfies the conditions.
Input
Input is given from Standard Input in the following format:
N S1 S2 ... SN T1 T2 ... TN U1 U2 ... UN V1 V2 ... VN
Output
If there exists a matrix that satisfies the conditions, print one such matrix in the following format:
a1,1 ... a1,N . . . aN,1 ... aN,N
Note that any matrix satisfying the conditions is accepted.
If no matrix satisfies the conditions, print −1−1.
Constraints
- All values in input are integers.
- 1≤N≤5001≤N≤500
- 0≤Si≤10≤Si≤1
- 0≤Ti≤10≤Ti≤1
- 0≤Ui<2640≤Ui<264
- 0≤Vi<264
Sample 1 Input
2
0 1
1 0
1 1
1 0
Sample 1 Output
1 1
1 0
In Sample Input 11, we need to find a matrix such that:
- the bitwise AND of the elements in the 11-st row is 11;
- the bitwise OR of the elements in the 22-nd row is 11;
- the bitwise OR of the elements in the 11-st column is 11;
- the bitwise AND of the elements in the 22-nd column is 00.
Sample 2 Input
2
1 1
1 0
15 15
15 11
Sample 2 Output
15 11
15 11