Problem A
The problem reduces to finding the longest string such that
- there are only characters in the string
- every characters are different
The answer is
Problem B
Suppose that you don't skip any floors. The distance you need to travel is
To figure out which floor to skip, we consider skipping each floor in the sequence, in particular to skip floor , the points is augmented by

Note that this works for all in . For the edge cases where or , the augmented points are simply and respectively. Note that it is only important to store the best net difference because we can apply the difference at the end.
Problem C
Two observations help simplify the problem:
- We can immediately lower bound by as choosing is possible if we choose , namely
- , .
Suppose we choose some . Let . Then as Namely, we see that it must be true then that Note that the biggest which divides is itself. Hence, it is clear that Without loss of generality, let us sort . Namely, this makes . The closest number to is . Hence,
Hence, the final answer must be the best of the two strategies, namely
Problem D
Problem D is a typical bitwise manipulation question. The order of the numbers we want to generate looks as follow:
1111111...
(i=1)
0111111...
(i=2)
0011111...
1011111...
(i=3)
0001111...
0101111...
1001111...
1101111...
...
This solution minimizes the number of bit positions whereby there exists a 0 in any row, while preserving a lexographical sorting. We systematically sacrifice the leftmost bits, and iterate thorugh all the permutations which require the sacrifice but have not appeared.
Notice that the rightmost bits are always 1s, the th bit is a 0, and the leftmost bits iterate through the ordered sequence (see underlined). Hence, in the solution, we generate 1s, and then shift into position.