QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#239049#7697. Impartial StringswillowAC ✓1ms3820kbC++171.4kb2023-11-04 18:14:492023-11-04 18:14:51

Judging History

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

  • [2023-11-04 18:14:51]
  • 评测
  • 测评结果:AC
  • 用时:1ms
  • 内存:3820kb
  • [2023-11-04 18:14:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 1e3 + 5;

char A[N], s[N], t[N];

int la, ls, lt;

bool check() {
    if(t[0] != t[1]) {
        bool ok = 1;
        for(int i = 1; i < lt - 1; ++ i) ok &= (t[i] == t[i + 1]);
        if(!ok) return 0;

        // if(s[ls - 1] != t[0]) return 0;
        for(int i = 1; i < lt; ++ i) ok &= (t[i] == s[i - 1]);
        return ok;
    }
    bool ok = 1;
    for(int i = 0; i < lt - 2; ++ i) ok &= (t[i] == t[i + 1]);
    if(!ok) return 0;
    if(t[lt - 1] == t[lt - 2]) {
        return 0;
    }
    // if(s[0] != t[lt - 1]) return 0;
    for(int i = 0; i < lt - 1; ++ i) {
        if(s[ls - i - 1] != t[0])return 0;
    }
    return 1;
}

void rmain() {
    scanf("%s%s%s", A, s, t);
    la = strlen(A), ls = strlen(s), lt = strlen(t);
    int cnt = 0;

    if(ls < lt) {
        swap(ls, lt);
        swap(s, t);
    }

    for(int i = 0; i < ls - lt + 1; ++ i) {
        bool ok = 1;
        for(int j = 0; j < lt; ++ j) {
            ok &= (s[i + j] == t[j]);
        }
        if(ok) ++ cnt;
    }
    if(cnt > 1) {
        puts("1");
        return;
    }
    if(cnt == 1) {
        puts("1");
        return;
    }
    if(la > 2) {
        puts("0");
        return;
    }
    
    if(check()) {
        puts("1");
    } else puts("0");

}

int main() {
    int T;
    for(cin >> T; T --;) {
        rmain();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3752kb

input:

3
ab ab ba
abc ab ba
cz cczz zzcc

output:

1
0
0

result:

ok 3 lines

Test #2:

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

input:

7
d d d
d dd d
d d dd
z zzzzzzzzzzzz zzz
a aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
1
1
1
1
1
1

result:

ok 7 lines

Test #3:

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

input:

10
ab aaaaaabbabbbbb bbbbba
ab aaaaaabbabbbbb baaaaaa
ab aaaaaabbabbbbb bbbba
ab aaaaaabbabbbbb bbba
ab aaaaaabbabbbbb baaa
ab aaaaaabbabbbbb baaaaa
ab aaaaaabbabbbbb baa
ab aaaaaabbabbbbb baaaa
ab aaaaaabbabbbbb baaaaaaa
ab aaaaaabbabbbbb bbbbbba

output:

1
1
1
1
1
1
1
1
0
0

result:

ok 10 lines

Test #4:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

50
az aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 3660kb

input:

50
az aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 50 lines

Test #6:

score: 0
Accepted
time: 1ms
memory: 3816kb

input:

50
az zaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 lines

Test #7:

score: 0
Accepted
time: 1ms
memory: 3664kb

input:

50
az azaaaaaaazaazzzzazzzaaaaaaaaaaaaaa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zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 lines

Test #10:

score: 0
Accepted
time: 1ms
memory: 3804kb

input:

50
az aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 50 lines

Test #11:

score: 0
Accepted
time: 1ms
memory: 3724kb

input:

50
az aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 lines

Test #12:

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

input:

50
ab bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 50 lines

Test #13:

score: 0
Accepted
time: 1ms
memory: 3820kb

input:

50
icp cppcpccpiccccccppiiiipicpcipicciciciccipcpcccpipcpppcipicipiipppipccppppiiippcpcpiciipcpipiipcccpiciiiicpipipcpcpicccpicppcciicippipcpicippcipppcppciiccicipccppccpccpipciipiippciippppicccciiicpciicpcppcipcippcppccipipcppcccppppciiccpippcipiipciccciccccccppipcccccicicpcppippciiccpiccppppccippc...

output:

0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 lines

Test #14:

score: 0
Accepted
time: 1ms
memory: 3808kb

input:

50
oks kksksoskssksskssksoksoskkkoooskkskskkkkkkokssksokoskkksooskkkokkkksosssoksskokokoksooosksskkkosssosoooskssokkooossskssssosossksoookkss koskskkkksssskkoossosskkskoskokokooksokossssokookkokosssoosoosskksokskskokkokokosookksokksokokooskokokkkkookosokooosoosksksoskkoookoskksksoskskssskoskskkkkskk...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

result:

ok 50 lines

Test #15:

score: 0
Accepted
time: 1ms
memory: 3684kb

input:

50
swxyrcjgp jjxypwcpgjxxcwccgwpsyxgjpwrgwpxwywwwxsxsyyygypwjrwpgcxgcgpgrrjwgjgpjsswjwpsjyxxyxscwcsxysywwyspgrspjsxypyyxsgyssswrcrpjgrygxwgjcyppysycpxyjjjgrgyxcwyywsrpyccrryprcjwgswrcjjgjxwyrpsgjpccrjwsjwxgjpsjssjycxxjprycxjxrpwgxcpjycwxyrgpppwwjjjcjrjxssxwyryxjyjjyjcjcsjsccpxxgscsspsryrjswpcwjgspsx...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
0
1
1
1
1
1
1
1
1
1

result:

ok 50 lines

Test #16:

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

input:

1
az aaaaza azaaaa

output:

0

result:

ok single line: '0'

Test #17:

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

input:

50
ab aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...

output:

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

result:

ok 50 lines