QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#829940 | #9925. LR String | CQXYM# | WA | 38ms | 7820kb | C++17 | 1.7kb | 2024-12-24 14:55:40 | 2024-12-24 14:55:46 |
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[1]=='R'&&s[1]=='L')
{
puts("NO");
continue;
}
int lens=len;
while(1)
{
if(s2[len2]=='L'&&s[lens]=='R')
{
puts("NO");
break;
}
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");
break;
}
if(sum[1]-sum[lens+1]>=len2) puts("YES");
else puts("NO");
break;
}
else
{
int num=len2-now;
int l=1,r=tot;
while(l<r)
{
int mid=(l+r+1)>>1;
if(sum[p[mid]]-sum[lens+1]>=num) l=mid;
else r=mid-1;
}
l=p[l];
if(sum[l]-sum[lens+1]<num)
{
puts("NO");
break;
}
now--;
while(now)
{
if(!l) break;
int op=0;
if(s2[now]=='R') op=1;
l=pr[l][op];
now--;
if(op==1) break;
}
if(!l)
{
puts("NO");
break;
}
if(!now)
{
puts("YES");
break;
}
lens=l-1;
len2=now;
}
}
}
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 7820kb
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: 38ms
memory: 7776kb
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'