Rating changes for last rounds are temporarily rolled back. They will be returned soon. ×

LegendaryNewbie_'s blog

By LegendaryNewbie_, history, 4 years ago, In English

VERDICT: Wrong Answer....the problem is about to find the length of the smallest palindrome that can be formed by adding some additional character at it end(possibly zero). i used prefix function of original given string comparing with its reverse to find out the largest suffix in the original string that is a prefix of its reverse that means palindromes.For several test case i found it working but verdict is "Wrong Answwer".Can anyone help me with test case or tell me reason why it may not work in this case.

int prefix_function(string original, string rev)
{
	string text = rev + '#' + original;

	int n = text.size();
	int m = original.size();

	vector<int>lps(n);

	for (int i = m + 1, j = 0; i < n; )
	{
		if (text[i] == text[j])
		{
			lps[i] = j + 1;
			j++;
			i++;
		}
		else
		{
			if (j != 0) j = lps[j - 1];
			else lps[i] = 0, i++;
		}
	}
	return lps[n - 1];
}

Full text and comments »

By LegendaryNewbie_, history, 4 years ago, In English

Can anyone please help me explaining the solution of this problem? I don't know how to solve this problem. Statement: We have a grid with H rows and W columns, Iroha is now standing in the top-left cell. She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.But she cannot enter the cells in the intersection of the bottom A rows and the leftmost B columns(that is there are A x B forbidden cells).Find the number of ways she can travel to the bottom-right cell. Problem Link

Full text and comments »