Sever Offline

The server was suddenly offline during the contest...

Z2541 Triple Numbers

Hint I
How can we generate valid Triple Numbers?

Hint II
We can utilize the functions to_string and stoll

Solution
Generate every Triple Numbers by looping from 1 to 9999 and concatenating three same numbers together. Then, count how many of them are within the range.

Z2542 Sandwich Numbers

Hint I Apply the solution of Triple Numbers to this task.

Solution
Generate every 3-digit, 5-digit, 7-digit, 9-digit sandwich numbers by bruteforcing the numbers between the 1s.
Handle the cases carefully!!! ($10121$ is a sandwich number)

Fun fact:
This is originally the third task, there was also a Fancy Number for Alice. But we decided not to use it since there would be too much strings.

Z2543 Fruit Subsequences

Hint I
Use a programme to turn the fruit names into a vector. (i.e. "banana, apple" -> "{"banana", "apple"}")

Hint II
The sum of lengths of fruit names is a lot less than length of $S$.

Solution
For each fruit name, find out whether it is a subsequence of string $S$ in around $O(|T|)$.
You can do by using a lot of different ways to do this, some common ways are

1. Store the position of every kind of character of string $S$, when matching subsequences, you can jump to the next character in $O(1)$

2. Store the positions appearing for every character, then do binary search for the index of closest character needed

Z2544 ID Number

Hint I
Brute force every x. How can we determine whether a x is valid?

Hint II
For checking a certain x, changed all the strings' x position to '$' and sort them. Check whether a[i] and b[i] are equal.

Solution
Combine hint I and hint II, brute force every x and check whether it is valid by performing hint II

Z2545 Pixel Stamper

Hint I
There are 4 directions only.

Hint II
Instead of adding the values to $B$$ij$ for every stamp, store the count for stamps in each direction

Solution
Apply Hint II, sum up each directions $B$$xy$ $\times count$$direction$
Time complexity: $O(N+Q)$