Two Hundred Twenty One (easy version) solution codeforces
This is the easy version of the problem. The difference between the versions is that the easy version does not require you to output the numbers of the rods to be removed. You can make hacks only if all versions of the problem are solved.
Stitch likes experimenting with different machines with his friend Sparky. Today they built another machine.
The main element of this machine arerods arranged along one straight line and numbered from to inclusive. Each of these rods must carry an electric charge quantitatively equal to either or (otherwise the machine will not work). Another condition for this machine to work is that the sign-variable sum of the charge on all rods must be zero.
More formally, the rods can be represented as an array ofnumbers characterizing the charge: either or . Then the condition must hold: , or .
Sparky charged allrods with an electric current, but unfortunately it happened that the rods were not charged correctly (the sign-variable sum of the charge is not zero). The friends decided to leave only some of the rods in the machine. Sparky has questions. In the th question Sparky asks: if the machine consisted only of rods with numbers to inclusive, what minimal number of rods could be removed from the machine so that the sign-variable sum of charges on the remaining ones would be zero? Perhaps the friends got something wrong, and the sign-variable sum is already zero. In that case, you don’t have to remove the rods at all.
If the number of rods is zero, we will assume that the sign-variable sum of charges is zero, that is, we can always remove all rods.
Help your friends and answer all of Sparky’s questions!
Each test contains multiple test cases.
The first line contains one positive integer( ), denoting the number of test cases. Description of the test cases follows.
The first line of each test case contains two positive integersand ( ) — the number of rods and the number of questions.
The second line of each test case contains a non-empty string +” symbol, or if is the “–” symbol.of length , where the charge of the -th rod is if is the “
Each next line from the nextlines contains two positive integers ans ( ) — numbers, describing Sparky’s questions.
It is guaranteed that the sum ofover all test cases does not exceed , and the sum of over all test cases does not exceed .
For each test case, print a single integer — the minimal number of rods that can be removed.
3 14 1 +--++---++-++- 1 14 14 3 +--++---+++--- 1 14 6 12 3 10 4 10 +-+- 1 1 1 2 1 3 1 4 2 2 2 3 2 4 3 3 3 4 4 4
2 2 1 0 1 2 1 2 1 2 1 1 2 1
In the first test case for the first query you can remove the rods numbered +–+–++-++-. It is easy to see that here the sign-variable sum is zero.and , then the following set of rods will remain:
In the second test case:
- For the first query, we can remove the rods numbered +–+–++-++-. It is easy to see that here the sign-variable sum is zero. and , then the following set of rods will remain:
- For the second query we can remove the rod numbered —++-. It is easy to see that here the variable sum is zero. , then the following set of rods will remain:
- For the third query we can not remove the rods at all.
Solution: Click here