#P17124. [ICPC 2025 Shanghai R] Not a subset sum

    ID: 19461 远端评测题 1000ms 1024MiB 尝试: 0 已通过: 0 显示难度普及+/提高− 上传者: 标签>2025上海深度优先搜索 DFS记忆化搜索ICPC

[ICPC 2025 Shanghai R] Not a subset sum

Problem Description

We are given an array a0,a1,,a2n1a_0, a_1, \cdots, a_{2^n - 1} of length 2n2^n. For a string qq of length nn over the alphabet 0,1,?0,1,? (11-indexed), define the "generalized subset sum" S(q)S(q) as the sum of aja_j over all indices jj that satisfy:

  • For each 1kn1 \le k \le n, if qk=0q_k = 0 then the kk-th bit of jj is 00.
  • For each 1kn1 \le k \le n, if qk=1q_k = 1 then the kk-th bit of jj is 11.
  • If qk=?q_k = ? there is no restriction on the kk-th bit of jj.

For example, when n=3n = 3 and s=0?1s = 0?1, the generalized subset sum is S(q)=a4+a6S(q) = a_4 + a_6 (binary 100100 and 110110). Note that the first bit is the lowest bit.

Your task is to compute the generalized subset sum for each string of length nn over the alphabet 0,1,?0,1,?. Because the total output can be large, you only need to output the bitwise XOR of all these sums.

Input Format

The first line of the input contains an integer nn (1n161 \le n \le 16).

The second line of the input contains 2n2^n integers a0,a1,,a2na_0, a_1, \cdots, a_{2^n} (0ai90 \le a_i \le 9), contents in array aa.

Output Format

Print an integer denoting the bitwise-XOR of all generalized subset sums.

1
3 5
14
2
2 6 8 8
0

Hint

The following are query strings qq and their corresponding generalized subset sums S(q)S(q) in sample 22:

q=00,S(q)=a0=2q = 00, S(q) = a_0 = 2

q=10,S(q)=a1=6q = 10, S(q) = a_1 = 6

q=?0,S(q)=a0+a1=2+6=8q = ?0, S(q) = a_0 + a_1 = 2 + 6 = 8

q=01,S(q)=a2=8q = 01, S(q) = a_2 = 8

q=11,S(q)=a3=8q = 11, S(q) = a_3 = 8

q=?1,S(q)=a2+a3=16q = ?1, S(q) = a_2 + a_3 = 16

q=0?,S(q)=a0+a2=10q = 0?, S(q) = a_0 + a_2 = 10

q=1?,S(q)=a1+a3=14q = 1?, S(q) = a_1 + a_3 = 14

q=??,S(q)=a0+a1+a2+a3=24q = ??, S(q) = a_0 + a_1 + a_2 + a_3 = 24

Now it is easy to verify that the output is 00.