DCEPC12B - Bits Game
Pranjali and Nancy are playing an amazing game. The game starts with a string of bits (i.e. string of 0’s and 1’s). Game progresses in the form of right to left bit by bit scans. Pranjali takes turn when a “1” bit comes while scanning the string and Nancy takes turn when a “0” bit comes while scanning. In their respective turns, they can either choose to toggle their bit or keep it unchanged. The goal is to make all bits 0 at the end of scan, failing which means the scanning starts again from right to left. If all the bits are 0 at the end of a scan, the game ends and Pranjali is declared a winner. There is no win for Nancy. The game either ends to the goal described or the scanning continues indefinitely. So it can be seen that Pranjali has to win the game and in an optimal number of scans whereas Nancy’s aim is to not let Pranjali win (by making it an indefinite play) or to delay Pranjali’s win if it’s sure. So now assuming that they both play with their optimal strategy, can you please tell if Pranjali can win the game or not?
Note: There has to be AT LEAST 1 scan before the game can end.
Input
First line contains T, the number of test cases.
Each of the next T lines contains a string of 0’s and 1’s.
Output
For each string given in the input, output either “WIN m”, without quotes, if Pranjali can force her win in “m” scans in an optimal play, or output “INFINITE PLAY” if the game cannot be reached to the above mentioned goal in an optimal play.
Constraints
1 <= T <= 20
1 <= Length of string <= 50
Example
Input: 2 1 10 Output: WIN 1 WIN 2
Explanation
In the 2nd test case, during the first scan, Nancy gets the first turn because the right most bit is 0. She has to toggle it or the game will be over in a single scan. In the next turn, Pranjali chooses to keep her bit unchanged. So after first scan, the string is now “11”. In the next scan, Nancy has no turns. So Pranjali will toggle both 1 bit and thus end the game.
hide comments
Flago:
2014-07-01 13:00:31
Good problem |
|
|RAMSDEN|:
2014-02-02 08:21:35
Enjoyed solving it |
|
wisfaq:
2013-12-28 21:07:23
Thanks for having made those problems available to more languages.
|
|
Mitch Schwartz:
2013-12-28 14:08:03
Agreed with wisfaq. |
|
wisfaq:
2013-12-28 14:08:03
I fail to see why this should result in language restrictions on SPOJ.
|
|
wisfaq:
2013-12-28 14:08:03
Is there any reason for language restrictions?
|
Added by: | dce coders |
Date: | 2013-12-07 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | C CSHARP C++ 4.3.2 CPP C99 HASK JAVA PAS-GPC PAS-FPC PYTHON PYTHON3 PY_NBC |