QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#841166 | #9925. LR String | ucup-team3586# | WA | 32ms | 9944kb | C++23 | 1.7kb | 2025-01-03 14:42:27 | 2025-01-03 14:42:28 |
Judging History
answer
#include<bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
using namespace std;
#define int long long
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
const int p=998244353;
int qp(int x,int y)
{
int res=1;
for(int t=x; y; y>>=1,t=1ll*t*t%p)
if(y&1) res=1ll*res*t%p;
return res;
}
char s[1<<20],t[1<<20];
int nxt1[1<<20];
int nxt2[1<<20];
int nxt3[1<<20];
signed main()
{
for(int T=read();T--;)
{
scanf("%s",s+1);
int n=strlen(s+1);
nxt1[n+1]=nxt2[n+1]=nxt3[n+1]=n+1;
for(int i=n; i>=1; --i)
{
nxt1[i]=nxt1[i+1];
nxt2[i]=nxt2[i+1];
nxt3[i]=nxt3[i+1];
if(i<n&&s[i]=='L'&&s[i+1]=='R') nxt1[i]=i;
if(s[i]=='L') nxt2[i]=i;
if(s[i]=='R') nxt3[i]=i;
}
for(int Q=read(); Q--;)
{
scanf("%s",t+1);
int m=strlen(t+1);
if(s[1]=='L'&&t[1]=='R')
{
puts("NO");continue;
}
if(s[n]=='R'&&s[1]=='L')
{
puts("NO");continue;
}
int p=1;
for(int i=1; i<=m; ++i)
if(t[i]=='L'&&(i<m&&t[i+1]=='R'))
{
// while(p<n&&(s[p]!='L'||s[p+1]!='R')) ++p;
if(p<n) p=nxt1[p];
if(p>=n){p=-1;break;}
else p+=2;
++i;
}
else if(t[i]=='L')
{
// while(p<=n&&s[p]!='L') ++p;
if(p<=n) p=nxt2[p];
if(p>n){p=-1;break;}
else ++p;
}
else
{
// while(p<=n&&s[p]!='R') ++p;
if(p<=n) p=nxt3[p];
if(p>n){p=-1;break;}
else ++p;
}
if(p==-1) puts("NO");
else puts("YES");
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9944kb
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: 32ms
memory: 9920kb
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 YES NO YES YES NO YES NO NO NO NO YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES YES 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...
result:
wrong answer 11th lines differ - expected: 'NO', found: 'YES'