Heap Dijkstra Revisited

View as PDF

Submit solution

Points: 10
Time limit: 0.2s
Memory limit: 1G

Author:
Problem type

Richard wants to demonstrate that there are things far worse than Fenwick in terms of things to remember, and the first example he gave was heap Dijkstra.

To demonstrate this, he wants a problem that has many edges, but doesn't benefit too much from fast I/O. So a natural candidate is https://szkopul.edu.pl/problemset/problem/ROXsaseQWYR11jbNvCgM19Er/site/?key=statement.

The algorithm in that problem is basically to construct a graph on the modulus against a1, and then do shortest path to look for the smallest number in each modulus that could be constructed.

Your job will be to solve this problem with some tuned bounds.

Input Specification

The first line contains a single integer, N.

N lines follow, each containing a single integer ai.

You may assume N100 and that 1ai240.

Furthermore, a1105.

Output Specification

Let xi be the smallest value that can be attained that is the sum of some multiset of ai values that is equivalent to i(moda1). Print the XOR of all xi for 0i<a1.

It is guaranteed that xi is well-defined.

Sample Input

Copy
6
10
1
11
22
33
478154081019

Sample Output

Copy
1
Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation.

Comments

There are no comments at the moment.