|
||||||||||
Great SequenceTime Limit: 10000/10000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submission(s): 314 Accepted Submission(s): 51 Problem Description A great sequence S is a sequence contains N decimal integers, i.e. S = (x[1], x[2], ..., x[N]). S should also satisfy following rules: a[i] ¡Ü x[i] ¡Ü b[i] ds[i] c[i] ds[i+1], where ds[i] is the digit sum of x[i] and c[i] is one of the following relational operators: "=", "<", "<=", ">", ">=" and "!=". Obviously, there are a lot of great sequences. You are asked to find the K-th least great sequence in lexicographic order. Input There are multiple test cases. Process to the End of File. The first line of each test case contains two integers 1 ¡Ü N ¡Ü 100, 1 ¡Ü K ¡Ü 1016, as described above. In the next N-1 lines, each line contains three elements, a[i], b[i] and c[i], where a[i] and b[i] are integers (1 ¡Ü a[i] ¡Ü b[i] ¡Ü 1018) while c[i] is one of the following strings: "=", "<", "<=", ">", ">=" and "!=". The last line of each test cases contains only two integers, a[N] and b[N] (1 ¡Ü a[N] ¡Ü b[N] ¡Ü 1018). Output For each test case, if the total number of great sequences is less than K, output "OUT OF RANGE" (without quotes); otherwise, output the K-th least great sequence in one line. Numbers in the sequence are separated by a single space. Sample Input
Sample Output
Author Zejun Wu (watashi) Source | ||||||||||
|