The Reversed WorldProblem code: REVERSED |
All submissions for this problem are available.
Given three numbers A, B and C all having N digits, little Johnny needs to write a program to permute the digits of the number C so that the new number is greater than both A and B.
This problem would be so easy if Johnny's teacher didn't require that Johnny's program must be correct in both the real world and the reversed world. What happens once the world is reversed? One thing Johnny knows for sure is that all the numbers are also reversed. The second thing, the "greater than" relation becomes the "smaller than" relation.
For the sake of clarity, we will use aR to denote the number a in the reversed world (for instance, 113R = 311).
Thus Johnny task is now permute the digits of C so that the new number is greater than both A and B. In additional, the reverse of the new number should be smaller than both AR and BR. If there are multiple possible solutions, Johnny needs to find the smallest one.
As usual, please help Little Johnny with his task!
Input
The first line contains a number T (about 10) which is the number of the test cases. Each test case has the following form.
The first line contains N (1 <= N <= 1000000).
The second line contains the number A.
The third line contains the number B.
The fourth line contains the number C.
Each test case's input is separated by a blank line.
Output
For each test case, print the solution in a single line. If there is no solution, print the number -1.
Example
Input: 2 2 12 23 32 3 124 324 335 Output: -1 353
| Author: | duc_admin |
| Date Added: | 11-03-2010 |
| Time Limit: | 3 sec |
| Source Limit: | 50000 Bytes |
| Languages: | ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, F#, FORT, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TEXT, WSPC |
Comments
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
HELP
Program should read from standard input and write to standard output. After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.

Fetching successful submissions

This is my first codechef
This is my first codechef program.
I had written the program in vc++ 2010 and it was running successfully, however after uploading the program here I realized that only c++ compilers supported here are 4.0-8 and 4.3.2 since I was getting syntax error, and runtime error afterwards on changing some of the code.
It seems there is much difference among the different c++ compilers. Is there any site where I can learn about supported syntax and functions of the two allowed compilers.