QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#835014 | #9925. LR String | ucup-team6274# | WA | 29ms | 3668kb | C++14 | 2.5kb | 2024-12-28 08:56:21 | 2024-12-28 08:56:23 |
Judging History
answer
#include<bits/stdc++.h>
bool Mbg;
using namespace std;
#define vec vector
#define pb push_back
#define eb emplace_back
#define siz(vec) ((int)(vec).size())
#define all(vec) (vec).begin(),(vec).end()
template<class T>
void operator +=(vec<T> &a,T b){a.push_back(b);}
template<class T>
void operator --(vec<T> &a){a.pop_back();}
#define pii pair<int,int>
#define x first
#define y second
#define mp make_pair
#define exc(exp) if(exp)continue;
#define stop(exp) if(exp)break;
#define ret(exp) if(exp)return;
#define deb(var) cerr<<#var<<'='<<(var)<<"; "
#define debl(var) cerr<<#var<<'='<<(var)<<";\n"
#define ins insert
#define era erase
#define lb lower_bound
#define int long long
#define inf (long long)(1e9)
template<class T>
bool Min(T &x,T y){return x>y?x=y,1:0;}
template<class T>
bool Max(T &x,T y){return x<y?x=y,1:0;}
const int mod=998244353;
void Add(int &x,int y){x=x+y<mod?x+y:x+y-mod;}
void Dec(int &x,int y){x=x>=y?x-y:x-y+mod;}
int fpm(int x,int y){
int ans=1;for(;y;y>>=1,(x*=x)%=mod)if(y&1)(ans*=x)%=mod;return ans;
}
int n,q,m;
char s[500010],t[500010];
int mch[500010][3];
bool sol(){
int i=1,j=0;
if(t[1]=='R'){
if(s[1]!='R')return 0;
i=2,j=1;
}
bool ed=0;
if(t[m]=='L'){
if(s[n]!='L')return 0;
ed=1;m--;
}
t[m+1]=' ';
for(;i<=m;i++){
if(t[i]=='L'&&t[i+1]=='R'){
j=mch[j+1][2];
i++;
}else if(t[i]=='L'){
j=mch[j+1][0];
}else{
j=mch[j+1][1];
}
}
if(j>n||ed&&j>=n){
return 0;
}
return 1;
}
void work(){
cin>>(s+1);
n=strlen(s+1);
s[n+1]='#';
mch[n+1][0]=mch[n+1][1]=mch[n+1][2]=n+1;
for(int i=n;i;i--){
memcpy(mch[i],mch[i+1],sizeof mch[i]);
if(s[i]=='L'){
mch[i][0]=i;
}
if(s[i]=='R'){
mch[i][1]=i;
}
if(s[i]=='L'&&s[i+1]=='R'){
mch[i][2]=i+1;
}
}
cin>>q;
while(q--){
cin>>(t+1);
m=strlen(t+1);
cout<<(sol()?"YES\n":"NO\n");
}
}
bool Med;
signed main(){
ios::sync_with_stdio(0),
cin.tie(0),cout.tie(0);
int T=1;cin>>T;while(T--)work();
// cerr<<"Time: "<<clock()<<" ms;\n";
// cerr<<"Memory: "<<abs(&Med-&Mbg)/1024.0/1024.0<<" MiB.\n";
}
/*
- CONTINUE, NON-STOPPING, FOR THE FAITH
- START TYPING IF YOU DON'T KNOW WHAT TO DO
- STOP TYPING IF YOU DON'T KNOW WHAT YOU'RE DOING
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3604kb
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: 29ms
memory: 3668kb
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 YES YES NO NO NO NO YES YES YES YES YES YES YES YES YES YES YES NO NO YES NO NO NO NO NO YES YES YES YES NO NO NO YES NO NO NO NO YES NO YES 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 YES YES...
result:
wrong answer 15th lines differ - expected: 'NO', found: 'YES'