| Task: | Sudoku |
| Sender: | |
| Submission time: | 2015-08-14 21:33:43 +0300 |
| Language: | Java |
| Status: | READY |
| Result: | 0 |
| group | verdict | score |
|---|---|---|
| #1 | WRONG ANSWER | 0 |
| test | verdict | time | |
|---|---|---|---|
| #1 | WRONG ANSWER | 0.28 s | details |
| #2 | WRONG ANSWER | 0.26 s | details |
| #3 | WRONG ANSWER | 0.21 s | details |
| #4 | WRONG ANSWER | 0.21 s | details |
| #5 | WRONG ANSWER | 0.22 s | details |
Code
//package putka2.sudoku;
import java.util.Scanner;
/**
*
* @author Adreno
*/
public class Putka2Sudoku {
public static int[][] s;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String syote = "" + input.nextInt();
s = new int[9][9];
for (int i=0; i<9; i++) {
s[0][i] = Integer.parseInt("" + syote.charAt(i));
}
ratkaise(1, 0);
for (int y=0; y<9; y++) {
for (int x=0; x<9; x++) {
System.out.print(s[y][x]);
}
System.out.println();
}
}
public static boolean ratkaise(int y, int x) {
boolean[] varatut = new boolean[10];
for (int i=0; i<y; i++) {
varatut[s[i][x]] = true;
}
for (int i=0; i<x; i++) {
varatut[s[y][i]] = true;
}
// blocks
int bX = 0;
if (x < 3) bX = 0;
else if (x < 6) bX = 3;
else bX = 6;
int bY = 0;
if (y < 3) bY = 0;
else if (y < 6) bY = 3;
else bY = 6;
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
varatut[s[bY+i][bX+i]] = true;
}
}
int nextY = y;
int nextX = x+1;
if (nextX == 9) {
nextX = 0;
nextY = y+1;
if (nextY == 9) {
for (int i=1; i<=9; i++) {
if (varatut[i]) continue;
s[y][x] = i;
return true;
}
}
}
for (int i=1; i<=9; i++) {
if (varatut[i]) continue;
s[y][x] = i;
if (ratkaise(nextY, nextX)) return true;
s[y][x] = 0;
}
return false;
}
}
Test details
Test 1
Verdict: WRONG ANSWER
| input |
|---|
| 592836471 |
| correct output |
|---|
| 592836471 836471592 471592836 928364715 364715928 ... |
| user output |
|---|
| 592836471 123457689 318249567 231564798 456178923 ... |
Test 2
Verdict: WRONG ANSWER
| input |
|---|
| 672935418 |
| correct output |
|---|
| 672935418 935418672 418672935 729354186 354186729 ... |
| user output |
|---|
| 672935418 123456789 314268597 231549876 456187923 ... |
Test 3
Verdict: WRONG ANSWER
| input |
|---|
| 329174658 |
| correct output |
|---|
| 329174658 174658329 658329174 291746583 746583291 ... |
| user output |
|---|
| 329174658 142356789 215468397 431285976 563719842 ... |
Test 4
Verdict: WRONG ANSWER
| input |
|---|
| 376958421 |
| correct output |
|---|
| 376958421 958421376 421376958 769584213 584213769 ... |
| user output |
|---|
| 376958421 124365789 415283697 231476958 543129876 ... |
Test 5
Verdict: WRONG ANSWER
| input |
|---|
| 875694321 |
| correct output |
|---|
| 875694321 694321875 321875694 756943218 943218756 ... |
| user output |
|---|
| 875694321 123457689 314278596 231546978 456129837 ... |
