QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#829872 | #9925. LR String | CQXYM# | WA | 39ms | 9908kb | C++11 | 1.5kb | 2024-12-24 14:23:54 | 2024-12-24 14:23:55 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int t,q;
char s[500005];
char s2[500005];
int last[2];
int pr[500005][2];
int sum[500005];
int p[500005],tot;
int main()
{
scanf("%d",&t);
while(t--)
{
int len;
scanf("%s",s+1);
len=strlen(s+1);
last[0]=last[1]=0;
for(int i=1;i<=len;i++)
{
pr[i][0]=last[0];
pr[i][1]=last[1];
if(s[i]=='L') last[0]=i;
else last[1]=i;
}
sum[len+1]=0;
for(int i=len;i>=1;i--) sum[i]=sum[i+1]+(s[i]=='R');
tot=0;
for(int i=1;i<=len;i++) if(s[i]=='L') p[++tot]=i;
scanf("%d",&q);
while(q--)
{
scanf("%s",s2+1);
int len2=strlen(s2+1);
if(s2[len2]=='L'&&s[len]=='R')
{
puts("NO");
continue;
}
if(s2[1]=='R'&&s[1]=='L')
{
puts("NO");
continue;
}
int now=0;
for(int i=len2;i>=1;i--)
{
if(s2[i]=='L')
{
now=i;
break;
}
}
if(!now)
{
if(s[1]=='L')
{
puts("NO");
continue;
}
if(sum[1]>=len2) puts("YES");
else puts("NO");
continue;
}
else
{
int num=len2-now;
int l=1,r=tot;
while(l<r)
{
int mid=(l+r+1)>>1;
if(sum[p[mid]]>=num) l=mid;
else r=mid-1;
}
l=p[l];
if(sum[l]<num)
{
puts("NO");
continue;
}
for(int i=now-1;i>=1;i--)
{
int op=0;
if(s2[i]=='R') op=1;
l=pr[l][op];
}
if(l) puts("YES");
else puts("NO");
}
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7780kb
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: 39ms
memory: 9908kb
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 NO YES YES YES YES NO NO NO YES YES NO YES NO NO NO NO YES YES YES YES YES YES YES YES YES YES YES NO NO YES NO NO NO NO NO NO YES YES YES NO NO NO NO NO NO NO NO YES NO NO NO YES YES NO NO NO NO NO NO NO NO NO YES YES YES YES YES YES YES NO NO NO NO YES NO NO YES YES YES NO NO NO NO...
result:
wrong answer 438th lines differ - expected: 'NO', found: 'YES'