QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#794198#8521. Pattern Search IIwangjunruiWA 20ms13188kbC++141.6kb2024-11-30 12:49:122024-11-30 12:49:13

Judging History

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

  • [2024-11-30 12:49:13]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:13188kb
  • [2024-11-30 12:49:12]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
constexpr int N = 1.5e5 + 5;
int n;
char str[N];
struct node
{
	int size, ans;
	int pref[N], preg[N];
	int suff[N], sufg[N];
	inline node friend operator+(const node &lhs, const node &rhs)
	{
		node res;
		res.size = lhs.size + rhs.size;
		res.ans = min(lhs.ans, rhs.ans);
		for (int i = 1; i <= n; ++i)
		{
			if (lhs.pref[i] == n + 1)
			{
				res.pref[i] = lhs.pref[i];
				res.preg[i] = lhs.preg[i];
			}
			else
			{
				res.pref[i] = rhs.pref[lhs.pref[i]];
				res.preg[i] = lhs.size + rhs.preg[lhs.pref[i]];
			}
			
			if (rhs.suff[i] == 0)
			{
				res.suff[i] = lhs.suff[i];
				res.sufg[i] = lhs.sufg[i];
			}
			else
			{
				res.suff[i] = lhs.suff[rhs.suff[i]];
				res.sufg[i] = lhs.sufg[rhs.suff[i]] + rhs.size;
			}
			if (lhs.suff[i] == 0 && rhs.pref[i + 1] == n + 1)
				res.ans = min(res.ans, lhs.sufg[i] + rhs.preg[i + 1]);
		}
		return res;
	}
} A, B;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	cin >> str;
	n = (int)strlen(str);
	if (n == 1)
	{
		cout << "1\n";
		return 0;
	}
	A.size = B.size = 1;
	for (int i = 1; i <= n; ++i)
	{
		if (str[i - 1] == 'a')
		{
			A.pref[i] = A.suff[i] = i;
			B.pref[i] = i + 1, B.suff[i] = i - 1;
			B.preg[i] = B.sufg[i] = 1;
		}
		else
		{
			B.pref[i] = B.suff[i] = i;
			A.pref[i] = i + 1, A.suff[i] = i - 1;
			A.preg[i] = A.sufg[i] = 1;
		}
	}
	A.ans = B.ans = INT_MAX;
	for (int i = 1; i <= 30; ++i)
	{
		swap(A, B);
		B = A + B;
	}
	cout << B.ans << '\n';
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 20ms
memory: 13188kb

input:

aabbaab

output:

9

result:

wrong answer 1st numbers differ - expected: '8', found: '9'