-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathURI1383Sudoku.java
More file actions
85 lines (77 loc) · 2.76 KB
/
URI1383Sudoku.java
File metadata and controls
85 lines (77 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/**
* See
* <a href="https://www.urionlinejudge.com.br/judge/en/problems/view/1383">Sudoku</a>
*
* @author Brian Yeicol Restrepo Tangarife
*/
public class URI1383Sudoku {
static BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws IOException {
int t = Integer.parseInt(in.readLine());
int instance = 0;
while (++instance <= t) {
boolean flag = true;
int n = 9;
int[][] sudoku = new int[n][n];
for (int i = 0; i < n; i++) {
String[] p = in.readLine().split("\\s");
int[] row = new int[n];
for (int j = 0; j < n; j++) {
row[j] = Integer.parseInt(p[j]);
}
sudoku[i] = row;
}
// Filas
for (int i = 0; i < n; i++) {
int[] aux = new int[n];
for (int j = 0; j < n; j++) {
if (aux[sudoku[i][j] - 1] == 0) {
aux[sudoku[i][j] - 1]++;
} else {
flag = false;
break;
}
}
}
// Columnas
for (int i = 0; i < n; i++) {
int[] aux = new int[n];
for (int j = 0; j < n; j++) {
if (aux[sudoku[j][i] - 1] == 0) {
aux[sudoku[j][i] - 1]++;
} else {
flag = false;
break;
}
}
}
int root = 3;
for (int i = 0; i < n; i += root) {
for (int j = 0; j < n; j += root) {
int[] aux = new int[n];
for (int k = i; k < i + root; k++) {
for (int l = j; l < j + root; l++) {
if (aux[sudoku[k][l] - 1] == 0) {
aux[sudoku[k][l] - 1]++;
} else {
flag = false;
i = n;
j = n;
k = i + root;
l = j + root;
}
}
}
}
}
out.println("Instancia " + instance);
out.println(flag ? "SIM\n" : "NAO\n");
}
out.close();
}
}