Submit | All submissions | Best solutions | Back to list |
Problem hidden on 2012-05-14 10:50:42 by :D
MAGICSQU - Magic Square! |
Given an nxn matrix, if it satisfy the next constraints it could be called a "Magic Square".
Constraints:
* The sum of the n rows, n columns and the two main diagonals of the matrix must be equal to the same number m, called magic constant
* the n2 positions of the matrix must contains natural numbers between 1 to n2, with no repetitions.
Input
Each test case consist in a natural number n (0 < n <= 20) denoting the matrix dimension. Then, the next n2 natural numbers will represent the values that initially contains the matrix.
For each position aij (1 <= i,j <= n) of the matrix, we have: 0 <= aij <= n2, for all ij.
A value of 0 in an initial position aij of the matrix means that you must find a number to complete that place. A non-zero value means that you cannot change that value for the given position.
Output
For each case you must print the case number (starting from 1).
Then, in the next n lines you must print the magic square if exists or the phrase ''No Solution'' (without the quotes) if doesn't exist a solution for the given initial configuration.
See the output example.
If for a given initial configuration exists more than one solution, you should give the lower one assuming a lexicographic order. For lexicographic comparison you should consider lines in first place.
Print a blank line between test cases.
For example:
2 7 6
9 5 1
4 3 8
it's lexicographically before than:
4 3 8
9 5 1
2 7 6
Example
Input:3
8 0 0
0 0 0
0 0 0
2
1 1
0 0
Output:
Case #1
8 1 6
3 5 7
4 9 2
Case #2
No Solution
Added by: | Coach UTN FRSF |
Date: | 2011-06-17 |
Time limit: | 1s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
hide comments
|
|||||
2011-07-04 08:32:21 blashyrkh
My solution ALWAYS returns lexicographically least magic square. But WA. Maybe Oleg is right... |
|||||
2011-07-04 05:32:05 Oleg
I asking it because maybe Coach UTN FRSF require compare not numbers, but result strings - in that case "13 4" < "2 4" Coach UTN FRSF, please check my last submission. |
|||||
2011-07-02 18:47:48 blashyrkh
@Krzysztof Lewko: Or maybe 1 2 15 16 12 14 3 5 13 7 10 4 8 11 6 9 ? |
|||||
2011-06-28 18:48:42 Oleg
Also think that something wrong with test cases or way you compare numbers. Please check my last submission. What output should be for 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ? also check a[i][j] <= N * N generates runtime error... Last edit: 2011-06-28 18:50:54 |
|||||
2011-06-18 16:28:29 Coach UTN FRSF
@:D the judge Ignores extra whitespaces @:[Trichromatic] XilinX For in cases where the matrix is completly empty, the n es really small. Initially did not want to limit n to consider cases where n can be relatively large and nearly complete the initial matrix. Or cases in where the n is large, but with no solution. Anyway I changed the problem statement for limit the n. Last edit: 2011-06-18 20:49:33 |
|||||
2011-06-18 16:21:06 [Rampage] Blue.Mary
@Coach UTN FRSF The response "there's no upper bound" is ridiculos. I can only think that there could be a test case with n=10000 (even though 99% of the board is fixed with numbers). If there's no upper bound on original problem description, you may look at the test case to find that. Or I'll hide this problem. Last edit: 2011-06-18 05:01:06 |
|||||
2011-06-18 16:21:06 :D
What kind of comparer is used? Are white spaces differences ignored? |
|||||
2011-06-18 16:21:06 Coach UTN FRSF
@blashyrkh Sir, the option a) 4 3 8 9 5 1 2 7 6 that you propose doesn't respect the problem statement because you change the 9 from the initial configuration that you describe: 4 9 0 0 0 0 0 0 0 Last edit: 2011-06-17 14:46:18 |
|||||
2011-06-18 16:21:06 blashyrkh
for input: 3 4 9 0 0 0 0 0 0 0 what should be the output?? a) 4 3 8 9 5 1 2 7 6 or b) 4 9 2 3 5 7 8 1 6 |
|||||
2011-06-18 16:21:06 Coach UTN FRSF
@blashyrkh Should be b) 4 9 2 3 5 7 8 1 6 without a doubt Last edit: 2011-07-13 12:17:20 |