QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#855110#9925. LR StringRepeaterWA 386ms3836kbC++202.0kb2025-01-12 14:47:432025-01-12 14:47:48

Judging History

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

  • [2025-01-12 14:47:48]
  • 评测
  • 测评结果:WA
  • 用时:386ms
  • 内存:3836kb
  • [2025-01-12 14:47:43]
  • 提交

answer

#include <bits/stdc++.h>

void solve()
{
	std::string s; std::cin >> s;
	int n = s.size();

	std::vector nxt(100, std::vector<int>(n, -1));
	std::vector<std::vector<int>> pos(100);
	std::vector<int> lst(100, -1), vis(n);
	for(int i = 0; i < n; i++)
	{
		if(lst[s[i]] != -1) nxt[s[i]][lst[s[i]]] = i;
		lst[s[i]] = i;
		pos[s[i]].emplace_back(i);
	}
	if(!pos['L'].empty()) 
	{
		nxt['L'][pos['L'].back()] = n;
		for(int i = 0; i < pos['L'][0]; i++) nxt['L'][i] = pos['L'][0];
	}
	if(!pos['R'].empty()) 
	{
		nxt['R'][pos['R'].back()] = n;
		for(int i = 0; i < pos['R'][0]; i++) nxt['R'][i] = pos['R'][0];
	}
	for(int i = 1; i < n; i++)
	{
		if(s[i] == 'R' && s[i - 1] == 'L') vis[i] = 1;
		nxt['L'][i] = std::max(nxt['L'][i], nxt['L'][i - 1]);
		nxt['R'][i] = std::max(nxt['R'][i], nxt['R'][i - 1]);
	}

	// for(int i = 0; i < n; i++) std::cout << nxt['L'][i] << " \n"[i == n - 1];
	// for(int i = 0; i < n; i++) std::cout << nxt['R'][i] << " \n"[i == n - 1];

	int q; std::cin >> q;
	std::vector<int> flg;
	for(int i = 0; i < n; i++) if(vis[i]) flg.emplace_back(i);
	while(q--)
	{
		std::string t; std::cin >> t;
		int m = t.size();

		if(m == 1)
		{
			if(t == "R" && s.front() == 'R') std::cout << "YES\n";
			else if(t == "L" && s.back() == 'L')  std::cout << "YES\n";
			else std::cout << "NO\n";
			continue;
		}
		if(t.front() == 'R' && s.front() != 'R')
		{
			std::cout << "NO\n";
			continue;
		}
		if(pos[t[0]].empty())
		{
			std::cout << "NO\n";
			continue;
		}

		int cur = pos[t[0]][0];
		bool ok = true;
		for(int i = 1, j = 0; i < m && cur < n; i++)
		{
			if(t[i - 1] == 'L' && t[i] == 'R')
			{
				if(j < flg.size()) cur = flg[j++] - 1;
				else 
				{
					cur = n;
					break;
				}
			}
			cur = nxt[t[i]][cur];
		}
		if(cur >= n) ok = false;

		if(ok) std::cout << "YES\n";
		else std::cout << "NO\n";
	}
}

/*
1
RRLRL
1
RLRLR
*/

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	int t; std::cin >> t;
	while(t--) solve();

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 386ms
memory: 3548kb

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

result:

wrong answer 32nd lines differ - expected: 'NO', found: 'YES'