QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865657 | #9925. LR String | jmnb | TL | 1ms | 8520kb | C++20 | 1.3kb | 2025-01-21 20:53:03 | 2025-01-21 20:53:05 |
Judging History
answer
#include <iostream>
#include<bits/stdc++.h>
#define N 200005
using namespace std;
struct stru
{
int head,end;
};
int a[N],T,n,fl,ans;
void read(int &x)
{
x=0;
int f=1;
char c=getchar();
while (c<'0' || c>'9')
{
if (c=='-') f=-1;
c=getchar();
}
while (c>='0' && c<='9')
{
x=x*10+c-'0';
c=getchar();
}
x*=f;
return;
}
char str[100001];
string s[100001];
int lenstr=0,lens[100001],nxt[100001],cnt[100001],p[100001];
signed main ()
{
scanf("%d",&T);
while (T--)
{ memset(lens,0,sizeof(lens));
memset(cnt,0,sizeof(cnt));
memset(nxt,0,sizeof(nxt));
scanf("%s",str);
lenstr=strlen(str);
scanf("%d",&n);
for (int i=1; i<=n; i++)
{
cin>>s[i];
lens[i]=s[i].size();
}
for (int i=1; i<=n; i++)
{
nxt[i]=i+1;
cnt[i]=0;
p[i]=i-1;
}
for (int i=0; i<lenstr; i++)
for (int j=1; j<=n; j=nxt[j])
{
if (str[i]==s[j][cnt[j]])
if (++cnt[j]==lens[j]) {
nxt[p[j]]=nxt[j];
p[nxt[j]]=p[j];
}
//cout<<"1";
}
for (int i=1; i<=n; i++) {
if(str[0]=='L'&&s[i][0]=='R') {
cout<<"NO"<<endl;
}
else if(str[lenstr-1]=='R'&&s[i][s[i].size()-1]=='L') {
cout<<"NO"<<endl;
}
else if (cnt[i]==lens[i]) printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8520kb
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
Time Limit Exceeded
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...