QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#615380#8467. Binary Stringslichenyu_acAC ✓69ms190084kbC++143.4kb2024-10-05 18:21:332024-10-05 18:21:33

Judging History

你现在查看的是最新测评结果

  • [2024-10-05 18:21:33]
  • 评测
  • 测评结果:AC
  • 用时:69ms
  • 内存:190084kb
  • [2024-10-05 18:21:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10,M=1e7+10;

int head[N],ver[M],nxt[M],tot=1;
void add(int x,int y){
    ver[++tot]=y,nxt[tot]=head[x],head[x]=tot;
}

int merge(int x,int y){
    return x==y?x:(x&&y?-1:x|y);
}

struct ACAM{
    int t[N][2],fail[N],cnt,End[N],val[N];

    void insert(char s[],int id){
        int p=0;
        for(int i=0;s[i];i++){
            int k=s[i]-'0';
            if(!t[p][k]){
                t[p][k]=++cnt;
                t[cnt][0]=t[cnt][1]=0;
                val[cnt]=End[cnt]=0;
            }
            p=t[p][k];
        }
        if(id)val[p]=merge(val[p],id);
        else End[p]=1;
    }

    void build(){
        queue<int>q;
        for(int i=0;i<2;i++)
            if(t[0][i])fail[t[0][i]]=0,q.push(t[0][i]);
        while(q.size()){
            int x=q.front();q.pop();
            val[x]=merge(val[x],val[fail[x]]),End[x]|=End[fail[x]];
            for(int i=0;i<2;i++){
                if(!t[x][i])t[x][i]=t[fail[x]][i];
                else fail[t[x][i]]=t[fail[x]][i],q.push(t[x][i]);
            }
        }
    }
}T;

int n,m;
int low[N],dfn[N],num,s[N],c[N],cnt,top,val[N],f[N][2],deg[N];
vector<int>g[N];
bool ins[N];
char str[N];

void clear(){
    for(int i=0;i<=T.cnt;i++){
        head[i]=0;
        dfn[i]=low[i]=ins[i]=s[i]=c[i]=0;
        val[i]=f[i][0]=f[i][1]=deg[i]=0;
        g[i].clear();
    }
    num=top=cnt=0;
    tot=1;
}

void tarjan(int x){
    low[x]=dfn[x]=++num,ins[x]=1,s[++top]=x;
    for(int i=head[x];i;i=nxt[i]){
        int y=ver[i];
        if(!dfn[y]){
            tarjan(y);
            low[x]=min(low[x],low[y]);
        }else if(ins[y])low[x]=min(low[x],dfn[y]);
    }
    if(dfn[x]==low[x]){
        int y;
        cnt++;
        do{
            y=s[top--],ins[y]=0,c[y]=cnt;
        }while(y!=x);
    }
}

void build(){
    for(int x=0;x<=T.cnt;x++)
        for(int i=0;i<2;i++){
            int y=T.t[x][i];
            if(T.End[x]||T.End[y])continue;
            add(x,y);
        }
}

void build2(){
    for(int x=0;x<=T.cnt;x++)
        for(int i=head[x];i;i=nxt[i]){
            int y=ver[i];
            if(c[x]!=c[y]&&c[x]&&c[y]){
                g[c[x]].emplace_back(c[y]);
                deg[c[y]]++;
            }
        }
}

void insert(int x,int val){
    if(!f[x][0]||f[x][0]==val)f[x][0]=val;
    else if(!f[x][1]||f[x][1]==val)f[x][1]=val;
}

bool topsort(){
    queue<int>q;q.emplace(c[0]);
    while(q.size()){
        int x=q.front();q.pop();
        if(val[x]==-1)return 1;
        if(val[x]&&f[x][0]&&val[x]!=f[x][0])return 1;
        if(val[x]&&f[x][1]&&val[x]!=f[x][1])return 1;
        if(val[x])insert(x,val[x]);
        for(auto y:g[x]){
            if(f[x][0])insert(y,f[x][0]);
            if(f[x][1])insert(y,f[x][1]);
            if(--deg[y]==0)q.emplace(y);
        }
    }
    return 0;
}

void solve(){
    scanf("%d%d",&n,&m);
    T.t[0][0]=T.t[0][1]=T.val[0]=T.End[0]=T.cnt=0;
    for(int i=1;i<=n;i++)scanf("%s",str),T.insert(str,i);
    for(int i=1;i<=m;i++)scanf("%s",str),T.insert(str,0);
    T.build(),clear(),build();
    tarjan(0);
    for(int i=0;i<=T.cnt;i++)
        if(!T.End[i])val[c[i]]=merge(val[c[i]],T.val[i]);
    build2();
    if(topsort())puts("YES");
    else puts("NO");
}

int main(){
    int T;scanf("%d",&T);
    while(T--)solve();
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 8ms
memory: 54848kb

input:

2
3 2
100
001
010
1001
000
2 4
100
001
010
1001
000
11

output:

YES
NO

result:

ok 2 token(s): yes count is 1, no count is 1

Test #2:

score: 0
Accepted
time: 0ms
memory: 56924kb

input:

2
2 4
01
10
00
11
0101
1010
2 2
0
1
01
10

output:

YES
NO

result:

ok 2 token(s): yes count is 1, no count is 1

Test #3:

score: 0
Accepted
time: 23ms
memory: 57196kb

input:

25000
2 1
01
01111
10
2 2
111
01
000
10
2 2
0
1111
10
11111
2 1
110
1
11
2 2
11
01
1101
0
2 2
01110
00101
111
1010
2 1
11010
10110
11
2 1
10101
0
001
2 2
01111
10010
000
10
2 2
10110
0
00
01110
2 2
10011
000
011
01
2 1
00
01110
100
2 2
0
0010
1000
1
2 1
0
00
1
2 2
0010
10111
10011
010
2 1
1000
0100
...

output:

YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
N...

result:

ok 25000 token(s): yes count is 12530, no count is 12470

Test #4:

score: 0
Accepted
time: 25ms
memory: 54880kb

input:

25000
2 1
001110
110
0011
2 1
01010
0
110
2 2
110101
10
11101
1000
2 1
010
01
101011
2 2
01110
1011
1001
11101
2 1
011
100111
110
2 1
00
1010
001010
2 2
001000
0110
10
010
2 2
101010
001010
000
0
2 2
010
1
10
10000
2 1
01
1
11
2 1
010
00111
111111
2 2
100011
11001
010
000001
2 1
0
0
1
2 2
11111
0101...

output:

NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
YES
NO
NO
NO
NO
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
...

result:

ok 25000 token(s): yes count is 13205, no count is 11795

Test #5:

score: 0
Accepted
time: 34ms
memory: 54848kb

input:

25000
2 2
00011
0000
111111
0
2 2
01101
0011011
101001
11
2 2
011
011
1
01100
2 2
10101
11111
01
010111
2 1
101010
01
11
2 1
00111
11001
00001
2 1
011
000110
1
2 1
01
0110111
1101011
2 2
0001001
10
011011
111001
2 2
11100
111
11001
101
2 2
1000
110110
000100
0111
2 1
000
011
111100
2 1
11110
00
1101...

output:

NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
...

result:

ok 25000 token(s): yes count is 13782, no count is 11218

Test #6:

score: 0
Accepted
time: 28ms
memory: 54940kb

input:

25000
2 2
1000110
00000
011
01
2 2
0001100
00
001
0111
2 1
0000
10
000110
2 2
001110
1110100
01011001
1100
2 2
00101110
111110
11101
0
2 1
01
1100
110101
2 2
01010001
0001111
00
10000
2 2
001100
10
0111
001011
2 1
01010
1001101
10111
2 2
101
011110
10001
010
2 2
1111011
00
11111110
010
2 2
01
100011...

output:

NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES...

result:

ok 25000 token(s): yes count is 14308, no count is 10692

Test #7:

score: 0
Accepted
time: 32ms
memory: 54852kb

input:

25000
2 1
1111111
0011
00
2 1
110
1111
01101
2 1
000
010
00010
2 1
11
1110
10
2 2
001100100
11111010
00001
1101101
2 1
011
000000
011110
2 2
0
1110101
1
00000111
2 2
011100100
1
0010111
000000
2 1
110011111
1
101010010
2 1
01
011011
01010011
2 1
0001001
1110
01100111
2 1
001110100
00
101101101
2 2
0...

output:

NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
NO
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
YES
YES
YES
N...

result:

ok 25000 token(s): yes count is 14837, no count is 10163

Test #8:

score: 0
Accepted
time: 35ms
memory: 54916kb

input:

25000
2 1
001011
0
0
2 2
000110
11100100
111
11011111
2 1
1001011110
110011
1100
2 2
11100010
1100100110
111010010
0
2 2
10
1
100110101
1
2 1
001
1110
11
2 2
1
100101111
00101100
1
2 1
010110
1101001
1101
2 1
011001011
000001
10
2 1
0111
10101
01101
2 1
111101
001
0
2 1
01
0
11
2 1
001101101
0011000...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YE...

result:

ok 25000 token(s): yes count is 15356, no count is 9644

Test #9:

score: 0
Accepted
time: 21ms
memory: 56952kb

input:

16666
2 1
00010
10
00
2 1
1
00001
1
2 1
11000
00000
00000
2 1
10101
000
1100
2 2
0
01101
01011
00
2 2
0011
10
1
100
3 1
100
0
011
011
3 1
0
01
011
1
3 1
1
11
10010
00
3 2
1111
1
11
0111
0
2 1
0
001
0111
3 3
10
001
01
000
11
01001
2 1
00011
00101
0000
2 2
1
000
11
0110
2 2
01010
00
1
0
3 3
01
10011
1...

output:

NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
NO
NO
YES
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
NO
NO
Y...

result:

ok 16666 token(s): yes count is 8153, no count is 8513

Test #10:

score: 0
Accepted
time: 23ms
memory: 54916kb

input:

16666
2 2
00
000011
11011
0100
3 3
101110
00
110
1
101
01
2 2
000110
01
11
011
2 2
000110
1
10001
0
2 3
01
101100
11
111011
010
3 2
011001
01
011
1
110100
3 2
111000
01111
10
01
100100
3 3
0011
00
101
00000
01000
00
2 3
01000
111011
110
011
01101
3 3
01111
0
10000
100101
110
011
2 2
01101
1100
1000
...

output:

YES
NO
NO
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
YES
YES
NO
NO
NO
YES
NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YE...

result:

ok 16666 token(s): yes count is 8546, no count is 8120

Test #11:

score: 0
Accepted
time: 24ms
memory: 56844kb

input:

16666
2 1
00010
0110101
1111110
2 1
1101101
01001
1011
3 1
001010
110100
0110000
111000
2 1
110011
000111
10101
3 3
1001000
1
11
1011000
0
001
2 3
110
00101
1101110
0101
01
3 1
1110010
100011
10
0
3 1
0111000
111001
000110
011110
2 1
10011
1
1000111
3 2
011
1100110
01
00011
110001
2 1
111
1101
0010
...

output:

YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
YES
YES
NO
YES
NO
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO...

result:

ok 16666 token(s): yes count is 8970, no count is 7696

Test #12:

score: 0
Accepted
time: 26ms
memory: 57196kb

input:

16666
2 2
1101010
10010011
0
0111
3 2
011110
1
1001
10
11011
2 1
1001001
110
10
3 1
100
0
1011111
0000010
3 1
10011111
00
1100
1011101
3 1
000
10011
000101
110
3 1
1101
0101111
11110
1111
2 3
000100
0100
0001101
0100101
01110110
2 3
01100
1
1010
10
1
2 1
1100101
1
111
3 2
00
1
000011
0
1010
3 3
10
0...

output:

NO
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO...

result:

ok 16666 token(s): yes count is 9238, no count is 7428

Test #13:

score: 0
Accepted
time: 27ms
memory: 54812kb

input:

16666
2 3
111
0
00011
0
0111100
2 1
100100100
1101
00
3 2
1001011
01010110
01
101111010
01001
3 2
0
110101
0000110
00010010
11110
2 3
11100001
1
110
00101111
00
3 1
10000
0110
101
11
3 2
000
1111
00101111
11101111
1111110
2 3
011101111
101000
0
0
001111101
2 3
010
00
01011
10100101
0
2 1
10
10
11100...

output:

NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
NO
YES
NO
NO
YES
NO...

result:

ok 16666 token(s): yes count is 9511, no count is 7155

Test #14:

score: 0
Accepted
time: 24ms
memory: 54848kb

input:

16666
2 1
0111
0100
00
2 3
1011011101
100110011
000
100010101
11111010
3 1
101010101
011001
1101000
01000
3 2
1
11010110
10111111
1
110
3 1
101
001000
111101
01011
2 2
00000
111000
1
00010110
3 2
011
00101100
00
101011001
0010001111
2 1
1010101
00
110111
2 2
111000
0
01010
01010
2 3
01101
110101
0
1...

output:

NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
...

result:

ok 16666 token(s): yes count is 9770, no count is 6896

Test #15:

score: 0
Accepted
time: 11ms
memory: 55136kb

input:

12500
2 2
00011
1100
111
10
4 1
0
01110
1
11001
01100
2 1
01
01011
0000
4 1
0
101
110
01
1
4 3
1011
00
0
101
11100
00
1
3 2
1100
10001
00110
1111
11
3 3
110
01
00111
01001
11
10
2 3
00100
10100
10111
01
0
4 2
1011
1
1110
00
101
11000
2 4
00101
1100
11100
00
0111
0
3 2
0111
111
00010
01111
10110
3 4
...

output:

NO
YES
YES
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
YES
YES
NO
NO
NO...

result:

ok 12500 token(s): yes count is 5851, no count is 6649

Test #16:

score: 0
Accepted
time: 16ms
memory: 54848kb

input:

12500
3 2
001110
00010
0
11
11100
2 3
01
00
00
10001
0000
4 1
01110
1101
1000
11100
000101
3 2
1
0
000
11110
00
4 1
00000
01
01
00
1011
4 1
1
1110
111110
110101
110101
2 2
00011
1
0
10
2 2
0
10000
010
10100
4 1
000
1011
10100
00
01
4 3
1
110110
001110
100010
111111
1001
101
3 1
0111
001000
010
11001...

output:

YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
NO
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
NO
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES
...

result:

ok 12500 token(s): yes count is 6171, no count is 6329

Test #17:

score: 0
Accepted
time: 18ms
memory: 54956kb

input:

12500
2 3
1100110
101110
10110
1001001
100
4 3
11
0010100
10000
0000000
0101101
000
0110
4 1
1001
11
1100
101001
1
4 1
010110
1010
11
0011
100111
2 4
000001
0
01
01
0
010011
3 4
101
1
100110
0
00
0100100
1101001
2 4
000
00
00111
111
010011
11
4 3
0
1001
0110011
0111
1
00
011011
2 3
1
1001010
11
1001...

output:

NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
NO
NO
YES
NO
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
NO
...

result:

ok 12500 token(s): yes count is 6366, no count is 6134

Test #18:

score: 0
Accepted
time: 23ms
memory: 55136kb

input:

12500
3 3
1101110
11
01111
1110001
0
1
3 1
11110
01101
1010
01
4 2
11111000
1
111
1111
10
001001
4 3
1000110
00010
000
1000101
00010
01
1
4 4
00101100
0011
01
11110110
01
111111
010
101
4 4
011010
110000
001011
00100
1101
0000000
1
010100
3 1
00001101
11101100
1000
01011
3 1
001
101110
1101
1111111
...

output:

NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
YES
YES
NO
YES...

result:

ok 12500 token(s): yes count is 6740, no count is 5760

Test #19:

score: 0
Accepted
time: 24ms
memory: 55132kb

input:

12500
3 3
1011
001111101
11011
1101011
1101100
0100
4 4
01
100
1110111
11101
1101
101010011
001
0
4 2
000
0010
1001
0
111
10001101
4 4
11110
1001
100110010
0110001
010
1
011
110
4 4
001011111
1111011
0
0111110
0110
10100
10101000
1000
2 2
1010
01100100
0
0011010
3 3
0
001
010
0111
0011
0111
2 2
0011...

output:

YES
NO
YES
NO
YES
NO
YES
NO
NO
YES
YES
YES
NO
NO
YES
NO
NO
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
NO
YES
YES
...

result:

ok 12500 token(s): yes count is 6794, no count is 5706

Test #20:

score: 0
Accepted
time: 22ms
memory: 57112kb

input:

12500
2 3
11100010
10
1100
1010110
0
4 3
011
11001
011010011
1100100011
01011
000011111
1000
4 4
1011001011
1101001101
0100101
1101100
10111100
0
110101110
11111
4 2
001
1111
1000101
010
00011
0010100111
3 4
00001
010
100
00010101
0010000
111000
11010111
4 2
0
011101010
10011101
101001010
101010101
...

output:

NO
YES
NO
YES
YES
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
NO
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
YES
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
YES
YE...

result:

ok 12500 token(s): yes count is 7037, no count is 5463

Test #21:

score: 0
Accepted
time: 16ms
memory: 54868kb

input:

10000
4 4
00
00
1110
010
1
1
1
1
4 4
0011
101
01011
1011
11111
001
0
0011
2 4
01001
111
00010
00
011
0011
5 2
0011
110
0
010
1101
111
0010
2 5
111
00111
111
0001
1
0
1
2 5
0001
1
11
000
10
010
0000
2 2
11111
1
101
0
3 2
0
11100
11
1
01110
4 1
1
1
010
01100
111
3 1
01000
001
11111
1111
2 1
010
0
10
2...

output:

YES
NO
NO
YES
NO
NO
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES
NO
NO
YES
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
...

result:

ok 10000 token(s): yes count is 4533, no count is 5467

Test #22:

score: 0
Accepted
time: 18ms
memory: 56924kb

input:

10000
4 5
01
1011
000100
11010
0
00
0
01
11
5 1
01111
01111
0
1
111
111001
4 3
001
011101
000001
001101
0
011
0
2 2
0
1
0110
1000
4 4
111
000
10110
11010
01011
100100
10000
000010
4 4
1011
0
0
0
100110
001010
100
11110
2 1
001001
00
00100
5 3
000100
011
111101
0
0101
001000
1
110
5 5
11
010111
10
00...

output:

NO
YES
NO
YES
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
YES
YES
YES
YES
YES
NO
NO
YES
NO
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
...

result:

ok 10000 token(s): yes count is 4793, no count is 5207

Test #23:

score: 0
Accepted
time: 23ms
memory: 55092kb

input:

10000
4 4
1
0101
001
00111
01
111
1011010
10
3 2
00001
01100
1
010
01001
2 3
0010001
0110
01000
100
10
5 4
1
0100111
1101
0
01000
011000
00
00
01000
4 3
1111011
10
01011
0010
010011
10
1011
3 2
110
10
1
00101
0
2 4
11100
1010
011000
1
011110
0
3 2
1
011100
111110
00
11
5 4
101100
11011
100
0101001
0...

output:

NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
NO
YES
YES
NO
NO
YES
NO
YES
YES
YES
NO
YES
NO
NO
NO
YES
...

result:

ok 10000 token(s): yes count is 4940, no count is 5060

Test #24:

score: 0
Accepted
time: 19ms
memory: 57180kb

input:

10000
4 2
1000000
01011
11
111001
0111100
10010
5 4
001011
000000
11100000
100010
101
110111
1111000
1
0
4 5
0001001
100111
10
10
01
10010
01011
011000
11001
3 1
010
01001001
1010
0
3 5
010
11
100
10101
0001
1
00
1111001
5 2
01100000
11000101
11
1101000
101
011111
001000
2 3
1011
00100001
1100
00000...

output:

YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
YES
NO
NO
YES
NO
YES
YES
NO
YES
YES
YES
NO
YES
NO
NO
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
NO
NO
NO
YES
NO
NO
YES
YES
NO
NO
N...

result:

ok 10000 token(s): yes count is 5114, no count is 4886

Test #25:

score: 0
Accepted
time: 19ms
memory: 56900kb

input:

10000
4 2
101100001
10001101
00111
1
111011011
01010
3 1
1100000
00
0110
10
2 1
0
0101
100
4 2
11011
01
001
00100111
01111000
100110
2 4
100100100
110011
100
11100101
1101000
0
3 2
00111101
11
1
10010
101111
5 2
01100001
011
0111
011100000
1000
0001100
000
2 3
0100100
00010000
101001110
001000
1
5 1...

output:

YES
NO
YES
YES
NO
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
YES
YES
NO
YES
NO
NO
NO
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
NO
NO
NO
NO
NO
YES
YES
YES
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
YES
NO
NO
NO
NO
YES
YES
Y...

result:

ok 10000 token(s): yes count is 5291, no count is 4709

Test #26:

score: 0
Accepted
time: 20ms
memory: 57180kb

input:

10000
4 1
101011
1011111
001100101
110
11011100
4 3
1
0
1
011
00
00001
1110111001
2 5
001000
00001
0010011
000010101
01101
1100010
00001
5 1
11
010010
00
0000110
01100000
0001111
4 1
01
000100110
000110
01110111
11111
4 3
0111010010
10
0001100
0111
1
0110001111
110010
3 1
010
0000000100
11111000
000...

output:

YES
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
NO
YES
YES
YES
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
NO
YES
NO
NO
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
YES
YES
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
YES
YES
YES
NO
YES...

result:

ok 10000 token(s): yes count is 5494, no count is 4506

Test #27:

score: 0
Accepted
time: 5ms
memory: 53072kb

input:

2
9561 4571
111111010
1000011001
1101111001110101110
000
100101
0100011001110
0010101101000001010
10
1101110101100001
10100001011001
11110001
001
1010101011001
000
111
101000110101000
1101
1100111100100110010
011001111010
10000010100111
00110100111111000
100
0001001
01010001
11110010010111
1100
1111...

output:

NO
NO

result:

ok 2 token(s): yes count is 0, no count is 2

Test #28:

score: 0
Accepted
time: 4ms
memory: 52844kb

input:

1
3445 1289
1
000111000
1101010111101111
1101010
0001100100101110011
1000010100010
01000100001
0000100
101001
1001001100
100111011000
1
001011100011010001
00101110000010000011
10111100110110
0
10011001
0
000011000111100
0110000111011000
00
101111101000000110
1
1111011
1100110
01000111
00010010110101...

output:

NO

result:

ok NO

Test #29:

score: 0
Accepted
time: 3ms
memory: 52884kb

input:

1
9974 5595
1
001001101000100101
010011000011110
1010101101101010
0100010011
00010
010100100
010000111101110
10111000100001110110
1111010
0000111101
011101111110
1010000110111101110
0111101000011000
01111001011111
011011
000110100011001
10001100010011
01001100110001110
0110000110000
1
0100100111
101...

output:

NO

result:

ok NO

Test #30:

score: 0
Accepted
time: 12ms
memory: 53116kb

input:

1
13292 19609
00110010111110100
01111000101
1101110111101111
1000101110
111010
0001
10100111110101001
1001010110101
0101100111001001110
01110101000000000
01111000111001110
00
00110010111111101101
01111111111001
0001111001011111
00111001100111
10011110111010101
1100110111101
0
000101100000000
1000000...

output:

NO

result:

ok NO

Test #31:

score: 0
Accepted
time: 69ms
memory: 190084kb

input:

1
2 2
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

NO

result:

ok NO

Test #32:

score: 0
Accepted
time: 28ms
memory: 121416kb

input:

1
2 1
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

YES

result:

ok YES

Test #33:

score: 0
Accepted
time: 15ms
memory: 82356kb

input:

1
99832 168
111101100111100011010011011000101011110101111010110111100001110110101111101000000111010111010101010110010111010011010011111001010111101100011110100111111100100111011101101001100011010101001001001001110100000000111001011111100010111101101010001000001001100111000001111001111000101100111010...

output:

NO

result:

ok NO

Test #34:

score: 0
Accepted
time: 15ms
memory: 82540kb

input:

1
99878 122
100111011100110101011100111101110011000011000111111000010110000100000001010011000000110110111110001010001000101010101010000111001011100111111001111011101001100001011011001011010111100110111100010011010101100001100010110101010000001101100000011000011101010000101111011011101110100100101011...

output:

NO

result:

ok NO

Test #35:

score: 0
Accepted
time: 13ms
memory: 82264kb

input:

1
99856 144
010111100111010000110100000010010011110010111001100011100111011001101100110011100011100111100111110010110110000010110100110000010110100110110100000011110111111110001000100000110101100001011110011110100000110000000000011100000100100010011001111100101101100110110011011000101010001001101001...

output:

YES

result:

ok YES

Test #36:

score: 0
Accepted
time: 19ms
memory: 82396kb

input:

1
99869 131
001111011110011011101011011111101000010101000110111000010111000001100001001000101110100110011110111000100100111111000000111110110010010001100001011010010111100000000111000010101000010001101101011110100001000001110011100011000010010010001011101001111110001011011000000110011101110011111010...

output:

NO

result:

ok NO

Test #37:

score: 0
Accepted
time: 15ms
memory: 82536kb

input:

1
99847 153
111101000100001111100000110011110100100001111001100111100000010101001001101101101000010101010101100101011001001100101110001000101010010000101100010010001011100110100101101010011110010110101000010110000000111100001010101001110101101110010001010101011010111100010110000101011001110011101010...

output:

YES

result:

ok YES

Test #38:

score: 0
Accepted
time: 17ms
memory: 82220kb

input:

1
99825 175
100101110111101000001110000110000111010000000110101110010001001111100110010111100111011100100100111101000111110100110010111010000110111011110111101110010011111100110010110101101110000111011011001111101101011101111000000010110101001101111010010000001010000011110000000011001011011010010001...

output:

NO

result:

ok NO

Test #39:

score: 0
Accepted
time: 23ms
memory: 85916kb

input:

1
99871 129
010101001100100001011111101001111111100111111011110101100011110111001011110110000110111101101101001011111100011101001000000100011010101111110010110110110100101011111001010111010000110000111100000111001100001110101011101001000011110101100010000100111010010101101110101010011111110010010001...

output:

NO

result:

ok NO

Test #40:

score: 0
Accepted
time: 19ms
memory: 84004kb

input:

1
99884 116
100100100100000111000111011010011001110110111010101100010100101100101011101111010111101000101011110100001000111010110110010111010010000100100011100100100110110000111000011000110010001010110001000111001110101101111111001011100101110100110000011001001010011101011011101101101011011111100001...

output:

YES

result:

ok YES