QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#834979 | #9925. LR String | ucup-team5318# | WA | 35ms | 3796kb | C++14 | 1.3kb | 2024-12-28 08:37:48 | 2024-12-28 08:37:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i,j,k) for(int i=(j);i<=(k);i++)
#define per(i,j,k) for(int i=(j);i>=(k);i--)
#define pb emplace_back
#define fi first
#define se second
using vi=vector<int>;
using pi=pair<int,int>;
void solve(){
string s; cin>>s;
int n=s.size();
vector< array<int,3> > nxt(n+1, {n, n, n});
per(i,n-1,0){
nxt[i]=nxt[i+1];
if(s[i]=='L'){
nxt[i][0]=i;
}
if(s[i]=='R'){
nxt[i][1]=i;
}
if(i<n-1 && s[i]=='L' && s[i+1]=='R'){
nxt[i][2]=i;
}
}
int q; cin>>q;
rep(_,1,q){
string t; cin>>t;
if(t[0]=='R' && s[0]!='R'){
cout<< "NO\n";
continue;
}
if(t.back()=='L' && s.back()!='L'){
cout<< "NO\n";
continue;
}
int pos=-1;
rep(i,0,(int)t.size()-1){
if(i<(int)t.size()-1 && t[i]=='L' && t[i+1]=='R'){
pos=nxt[pos+1][2]+1;
i++;
}
else if(t[i]=='L'){
pos=nxt[pos+1][0];
}
else if(t[i]=='R'){
pos=nxt[pos+1][1];
}
if(pos==n){
break;
}
}
cout<< (pos<n? "YES": "NO") <<'\n';
}
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
#ifndef ONLINE_JUDGE
assert(freopen(".in","r",stdin));
assert(freopen(".out","w",stdout));
#endif
int t; cin>>t;
while(t--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
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: 35ms
memory: 3796kb
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 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 Y...
result:
wrong answer 47th lines differ - expected: 'NO', found: 'YES'