String Table
Time limit2sMemory limit512 MB
Build a table whose cells are huge concatenated strings defined by comparing neighbors, then print 50 characters from a given position of the final cell.
- Level
Hard8 of 10
- Topics
- Dynamic programming, String, Recursion, Divide and conquer
- Solved
- No attempts yet
Problem
You are given two strings and . All characters in the two strings are distinct: no character appears twice, no character of appears in , and no character of appears in .
Let be the length of and the length of . A two-dimensional array table is defined as follows.
table[i][0] = s[i-1]()table[0][j] = t[j-1]()table[i][j] = min(table[i-1][j], table[i][j-1]) + max(table[i-1][j], table[i][j-1])(, )
min returns whichever of the two strings comes first in lexicographic order, and max returns the one that comes later. Characters are compared by ASCII code, so digits come before uppercase letters and uppercase letters come before lowercase letters. A+B is the string A followed by the string B.
Write a program that finds a substring of table[N][M]. Because the string can be very long, print only the characters starting at position . Here is the length of table[N][M], and positions are counted from 0.
Input
The first line contains , the second line contains , and the third line contains ().
The lengths of and are each between 1 and 30, inclusive. Both strings consist only of uppercase letters, lowercase letters, and digits.
Output
Print, on the first line, the substring of table[N][M] that consists of the characters starting at position .