QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#865037#9925. LR Stringpiggy123#WA 32ms7904kbC++173.3kb2025-01-21 14:09:202025-01-21 14:09:21

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 14:09:21]
  • 评测
  • 测评结果:WA
  • 用时:32ms
  • 内存:7904kb
  • [2025-01-21 14:09:20]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll nxtL[500005],nxtR[500005],nxtLR[500005],lstL,lstR,lstLR;

int main(){
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(false);
	ll t;
	cin >> t;
	while (t--){
		string s;
		cin >> s;
		ll n=s.length();
		s='*'+s;
		lstL=lstR=lstLR=n+1;
		for (ll i=n;i>=0;i--){
			nxtL[i]=lstL;
			nxtR[i]=lstR;
			nxtLR[i]=lstLR;
			if (i>0){
				if (i<n&&s[i]=='L'&&s[i+1]=='R')lstLR=i+1;
				if (s[i]=='L')lstL=i;
				if (s[i]=='R')lstR=i;
			}
		}
		ll q;
		cin >> q;
		for (ll i=1;i<=q;i++){
			string t;
			cin >> t;
			ll ps=0;
			for (ll j=0;j<t.size();j++){
				if (j+1<t.size()){
					if (t[j]=='L'&&t[j+1]=='R'){
						ps=nxtLR[ps];	
						j++;
					}else{
						if (t[j]=='L')
						ps=nxtL[ps];
						else
						ps=nxtR[ps];
					}
				}else{
					if (t[j]=='L')
					ps=nxtL[ps];
					else
					ps=nxtR[ps];
				}
				if (ps>n)break;
			}
			if (ps>n){
				cout<<"NO\n";
			}else{
				cout<<"YES\n";
			}
		}
	}
	return 0;
}

/*
                                                                
 ■■■■■     ■■      ■■■     ■■■   ■    ■     ■     ■■■■    ■■■■  
 ■   ■■    ■■     ■  ■■   ■  ■■  ■    ■    ■■     ■  ■■  ■■  ■  
 ■    ■    ■■    ■    ■  ■    ■   ■  ■    ■■■    ■■  ■■  ■   ■■ 
 ■    ■    ■■    ■    ■  ■    ■   ■  ■     ■■    ■   ■■      ■■ 
 ■    ■    ■■    ■       ■         ■■      ■■        ■■      ■  
 ■   ■■    ■■    ■  ■■■  ■  ■■■    ■■      ■■       ■■     ■■■  
 ■■■■■     ■■    ■    ■  ■    ■    ■■      ■■      ■■        ■■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■■          ■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■      ■   ■■ 
 ■         ■■    ■■  ■■  ■■  ■■    ■■      ■■    ■       ■■  ■■ 
 ■         ■■      ■■■■    ■■■■    ■■      ■■    ■■■■■■   ■■■■  
*/

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 7904kb

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: 7780kb

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
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
N...

result:

wrong answer 5th lines differ - expected: 'NO', found: 'YES'