Professional Documents
Culture Documents
BGC2012 Contest
BGC2012 Contest
BGC2012 Contest
Setter: Mohammad Mahmudur Rahman Tester: Md. Towhidul Islam Talukder Category: Pre-school No need for an analysis. If you need a challenge, try to solve it with Max-Flow. ;-)
if (1) returns equal (the suffixes have equal prefix of length s-len+b), Let, l1 = s+len-b, l2 = s+len-a 2. f(a + l1, s, s+len-a) compares suffixes at a + l1 and s with length of the suffix at s+lena if (2) return equal. 3. f(s,b+l2,len-l1-l2) compares suffixes at s and b+l2 with length of the suffix at len-l1-l2. f(a, b, len) is computed the following way: return equal : if lcp(a,b) >= len return f(a + lcp(a,b), b + lcp(a,b)) The general algorithm is the following: for each left and right position (a,b) of the substring: idx := a for each c in (a <= c <= b): if (comp(a, idx, c, b-a+1)) idx := c check and insert rotation of substring (a,b) starting at idx into the trie if not found. increment the answer counter if its a new substring The overall complexity is O(N^3). There is another algorithm which can find the minimum lexicographic rotation in O(N). It is described here: (http://online-judge.uva.es/board/viewtopic.php? t=42601&f=22#p132758) This problem can be solved using Suffix Automata too.
Problem G: I am dumb 3
Setter: Md. Mahbubul Hasan Tester: Jane Alam Jan Category: Game theory Unfortunately, a similar problem came as division 1 hard of SRM 309. Actually its quite difficult to assure whether a problem appeared before in a contest or not with so many contests and online judges these days. Not too bad if you solved that before ;-). If you didnt, it's better to read the editorial of that SRM. (http://community.topcoder.com/tc?module=Static&d1=match_editorials&d2=srm309)
Say we are at range[1,4]. Its childs are [1,2] and[3,4]. Left child has a1 and a2. Q(1,2) can be written as: a1 +a2 +a2
The right child has a3 and a4. Q(3,4) can be written as: a3 +a4 +a4
From the desired sum of Q(1,4) see the red and blue part in that. And the green part too. a1 +a2 a2 +a3 +a3 +a3 +a4 +a4 +a4 +a4
The red part is the query sum of [1,2], blue part is the query sum of [3,4]. And the green part is actually the number of items in the left subtree times the sum of items in the right subtree (In this example: 2 items in [1,2] and the green part equals 2*(a3+a4).) So the formula should be: Q(i, j) = Q(i, m) + Q(m+1, j) + (m - i + 1) * S(m+1, j) [ here m = (i + j) / 2] S(i, j) = S(i, m) + S(m+1, j) [ S(i, i) = value at i-th index of the array] I wont go into the details of implementation.