Блог пользователя LegendaryNewbie_

Автор LegendaryNewbie_, история, 5 лет назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

Автор LegendaryNewbie_, история, 5 лет назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится