CodeForces - 1221E Game With String (inequality Game)

Alice and Bob play a game. Initially they have a string s1,s2,,sns1,s2,…,sn, consisting of only characters . and X. They take alternating turns, and Alice is moving first. During each turn, the player has to select a contiguous substring consisting only of characters . and replaces each of them with X. Alice must select a substing of length aa, and Bob must select a substring of length bb. It is guaranteed that a>ba>b.

For example, if s=s= ...X.. and a=3a=3, b=2b=2, then after Alice's move string can turn only into XXXX... And if it's Bob's turn and the string s=s= ...X.., then after Bob's move the string can turn into XX.X.., .XXX.. or ...XXX.

Whoever is unable to make a move, loses. You have to determine who wins if they both play optimally.

You have to answer qq independent queries.

Input

The first line contains one integer qq (1q31051≤q≤3⋅105) — the number of queries.

The first line of each query contains two integers aa and bb (1b<a31051≤b<a≤3⋅105).

The second line of each query contains the string ss (1|s|31051≤|s|≤3⋅105), consisting of only characters . and X.

It is guaranteed that sum of all |s||s| over all queries not exceed 31053⋅105.

Output

For each test case print YES if Alice can win and NO otherwise.

You may print every letter in any case you want (so, for example, the strings yEs, yes, Yes and YES will all be recognized as positive answer).

Example

Input
3
3 2
XX......XX...X
4 2
X...X.X..X
5 3
.......X..X
Output
YES
NO
YES

Note

In the first query Alice can select substring s3s5s3…s5. After that ss turns into XXXXX...XX...X. After that, no matter what move Bob makes, Alice can make the move (this will be her second move), but Bob can't make his second move.

In the second query Alice can not win because she cannot even make one move.

In the third query Alice can choose substring s2s6s2…s6. After that ss turns into .XXXXX.X..X, and Bob can't make a move after that.

 

That Italy: T sets of data, each group for a string of 'X' and composition '.'. Now Alice and Bob take turns playing the game, Alice first operation.
For each operation a continuous Alice can be a '.' Into 'X', Bob can consecutive b '' into 'X-'. (Greater than a guaranteed input b)
who can not operate who will lose.

First of each successive '' present in the array num process inside out.
:( great ideas for topics for Bob advantage) we assume that Bob upper hand (the upper hand to win the case Bob is a good question), to find out the circumstances of Bob upper hand to win, so long as the operation after it for Alice As long as the situation is not a situation to win the upper hand so Bob and Alice win.

Bob conditions to win the upper hand:

 1. presence num [i] satisfies b≤num [i] <a is smaller than b as a so Alice can operate num [i] Bob can operate, not vice versa. Bob just need to manipulate the final num [i] will be able to meet the conditions to win.
 2. The presence of num [i] satisfies 2 * [i] b≤num because then one can separate a section of b≤num [i] <a is a condition, according to the conditions is a win Bob Bob upper hand operation.
 3. meet a≤num [i] <2 * b is a number odd number. Because both Alice or Bob can only operate on him once, just odd last operation is Bob, he will prevail.
Alice just need to avoid the upper hand after handling these three will be able to become the winner.

Reference Code:

#include<bits/stdc++.h>
using namespace std;
typedef long long  ll;
const int manx = 300100;
char str[manx];
int a[manx];
int n;
ll  x,y;
int fid()
{
    for(int i=1; i<=n; i++)
        if(a[i]>=y&&a[i]<x) return 0;
    int to=0,k,cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]>=x) cnt++;
        if(a[i]>=y*2) to++,k=a[i];
    }
    if(to>=2) return 0;
    if(cnt%2==1)
    {
        if(to)
        {
            if((3*x<=k&&k<=4*y-2+x )|| (x<=k&&k<=2*y-2+x))
                return 1;
            else return 0;
        }
        else return 1;
    }
    else
    {
        if(to)
        {
            if(2*x<=k&&k<=3*y-2+x) return 1;
            else return 0;
        }
        else return 0;
    }
}
int main()
{
    int T;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld%lld",&x,&y);
        scanf("%s",str+1);
        int len=strlen(str+1);
        n=0;
        for(int i=1;i<=len;)
        {
            if(str[i]=='X'){i++;continue;}
            int xx=0;
            while(str[i]=='.') xx++,i++;
            a[++n]=xx;
        }
        int flag=fid();
        if(flag) puts("YES");
        else puts("NO");
    }
    return 0;
}
 
View Code

 

Guess you like

Origin www.cnblogs.com/songorz/p/11635445.html