Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么一直超时不是实现了manacher吗

Posted by JeremyCorbyn at 2018-01-21 18:57:07 on Problem 3974
#include<iostream>
#include<string>

int main()
{
	int id = 1;
	std::string s;
	std::cin >> s;
	while (s != "END")
	{
		for (int i = 0; i <= s.length(); i += 2)
			s.insert(i, "#");
		int lenmax = 1, r = 0, c = 0;
		int* len=new int[2000001];
		for (int i = 0; i < s.length(); i++)
		{
			int j;
			if (i < r)
				len[i] = len[2 * c - i] < r + 1 - i ? len[2 * c - i] : r + 1 - i;
			else
				len[i] = 1;
			for (j = len[i]; i - j > -1 && i + j < s.length(); j++)
				if (s[i - j] != s[i + j])
					break;
				else
					len[i]++;
			if (len[i] > lenmax)
				lenmax = len[i];
			if (i + len[i]-1 > r)
			{
				r = i + len[i]-1;
				c = i;
			}
		}
		std::cout << "Case " << id++ << ": " << lenmax - 1 << std::endl;
		delete len;
		std::cin >> s;
	}
	return 0;
}
吐血

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator