DCEPC12B - Bits Game

no tags 

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.
Could you do the same with:
http://www.spoj.com/problems/DCEPCA03/
and
http://www.spoj.com/problems/DCEPC11I/

reply - Done.

reply: Thanks

Last edit: 2013-12-29 14:18:41
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.
Language restrictions on SPOJ should only be problem oriented. Not source oriented.
So please remove language restrictions from all your contributions.

reply - I agree with your point. My intention was to be sure in whatever limits/constraints I have set in my problems because I am not fully aware of capabilities/limitations of other languages. I will open up my problems in other common languages too. But although I set reasonable limits in my problems, I don't have test solutions in other languages and so I urge the community to help me correct any language specific mistake, if it arises.

Last edit: 2013-12-28 14:01:35
wisfaq: 2013-12-28 14:08:03

Is there any reason for language restrictions?

reply - this is a problem from an ICPC style contest. hence the language restrictions.

Last edit: 2013-12-27 09:36:25

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