QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#834973#9925. LR Stringucup-team5318#WA 31ms3824kbC++141.3kb2024-12-28 08:35:092024-12-28 08:35:09

Judging History

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

  • [2024-12-28 08:35:09]
  • 评测
  • 测评结果:WA
  • 用时:31ms
  • 内存:3824kb
  • [2024-12-28 08:35:09]
  • 提交

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];
				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();
	}
}

詳細信息

Test #1:

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

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: 31ms
memory: 3824kb

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...

result:

wrong answer 101st lines differ - expected: 'NO', found: 'YES'