QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#847645#9925. LR Stringc20230201#WA 27ms11880kbC++142.3kb2025-01-08 09:04:062025-01-08 09:04:08

Judging History

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

  • [2025-01-08 09:04:08]
  • 评测
  • 测评结果:WA
  • 用时:27ms
  • 内存:11880kb
  • [2025-01-08 09:04:06]
  • 提交

answer

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

const int maxn=5e5+5;

char s[maxn], t[maxn];
int s1[maxn], s2[maxn];

int fa[maxn], fa2[maxn];

int find(int x) {
    if(fa[x]!=x) return fa[x]=find(fa[x]);
    return x;
}

int find2(int x) {
    if(fa2[x]!=x) return fa2[x]=find2(fa2[x]);
    return x;
}

void solve() {
    cin>>s+1;
    int n=strlen(s+1);
    int cl=0, cr=0, tot=0;
    for(int i=1;i<=n;i++) {
        if(s[i]=='L') {
            if(!cr) cl++;
            else {
                s1[++tot]=cl, s2[tot]=cr;
                cl=1, cr=0;
            }
        }else cr++;
    }
    s1[++tot]=cl, s2[tot]=cr;
    for(int i=1;i<=tot+1;i++) fa[i]=i, fa2[i]=i;
    for(int i=1;i<=tot;i++) {
        if(!s1[i]) fa[i]=i+1;
        if(!s2[i]) fa2[i]=i+1;
        // cout<<s1[i]<<' '<<s2[i]<<'\n';
    }
    int q; cin>>q;
    while(q--) {
        cin>>t+1;
        int m=strlen(t+1);
        int cr=0;
        int sum=0, sum2=0, pos=1;
        int flag=0;
        for(int i=1;i<=m;i++) {
            if(t[i]=='L') {
                if(!cr) {
                    if(!sum) {
                        pos=find(pos);
                        if(pos==tot+1) {
                            flag=1;
                            break;
                        }
                        sum+= s1[pos], sum2=s2[pos];
                        pos++;
                    }
                }else {
                    pos=find(pos);
                    if(pos==tot+1) {
                        flag=1;
                        break;
                    }
                    sum=s1[pos], sum2=s2[pos];
                    pos++;
                }
                cr=0;
                sum--;
            }else {
                cr++;
                if(!sum2) {
                    pos=find2(pos);
                    if(pos==tot+1) {
                        flag=1;
                        break;
                    }
                    sum=0, sum2=s2[pos];
                    pos++;
                }
                sum2--;
            }
        }
        if(flag) cout<<"NO\n";
        else cout<<"YES\n";
    }
    return ;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t; cin>>t;
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 9752kb

input:

2
RRLLRRLL
4
LLLLL
LLR
LRLR
R
RLLLLLL
3
LLLLL
RL
RRL

output:

NO
YES
NO
YES
YES
YES
NO

result:

ok 7 lines

Test #2:

score: -100
Wrong Answer
time: 27ms
memory: 11880kb

input:

100000
RRLLR
4
R
R
R
R
LRLLL
6
R
L
L
L
L
R
RLLRR
1
L
LRLLL
3
R
L
L
RLRRL
2
LRRRR
RRRL
LRLRR
2
L
R
RRLRL
4
RLRLR
RLLL
LR
RLL
RLRLL
8
R
R
R
L
L
L
R
L
RLLRR
7
R
LL
RL
R
L
L
L
LLRLR
2
L
R
RRRRL
1
RLLLR
RRLLL
2
L
L
RLLRL
1
RLLRL
LRLLL
5
RLRLL
RLLLR
RRRRL
LLRRR
RLLRR
LRLLL
3
RRLL
R
RL
LLRRL
3
L
R
LLLRR
RR...

output:

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

result:

wrong answer 5th lines differ - expected: 'NO', found: 'YES'