Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

TANGLED - Editorial

$
0
0

PROBLEM LINKS

Practice

Contest

DIFFICULTY

Hard

PRE-REQUISITES

Suffix Arrays

Problem:

As stated on the problem statement:

For a string S=c1 c2 ... cN, let S[a,b] denote ca ca+1 ... cb-1 cb, that is, the substring starting at ath character and ending at bth character. For each 1 ≤ i ≤ L, chef wants the children to know how many tuples (a, b, c, d) exist for which S1[a, b] = S2[c, d] and length of S1[a,b] is i.

Quick explanation:

We can use the concept of suffix arrays to solve the problem along with the use of a stack data structure to solve queries fast.

Detailed explanation:

The most naive solution for this problem has complexity O(N^2) and it involves checking all possible substrings of a string on the other string.

This solution solves Subtasks 1 and 2 only...

For the remaining subtasks O(NlogN) solution needs to be devised using the concept of Suffix Arrays...

(Under construction...)

Solutions:

Setter

Tester

Further helpful links to consult:

Suffix Array

LCP Array

GInfo paper on "Suffix Arrays: A programming contest approach"


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>