Task: | Ruudukko |
Sender: | odporkka |
Submission time: | 2019-05-30 22:36:43 +0300 |
Language: | Java |
Status: | READY |
Result: | 12 |
group | verdict | score |
---|---|---|
#1 | ACCEPTED | 12 |
#2 | RUNTIME ERROR | 0 |
#3 | RUNTIME ERROR | 0 |
test | verdict | time | group | |
---|---|---|---|---|
#1 | ACCEPTED | 0.18 s | 1 | details |
#2 | ACCEPTED | 0.18 s | 1 | details |
#3 | ACCEPTED | 0.18 s | 1 | details |
#4 | ACCEPTED | 0.19 s | 1 | details |
#5 | ACCEPTED | 0.18 s | 1 | details |
#6 | RUNTIME ERROR | 0.18 s | 2 | details |
#7 | RUNTIME ERROR | 0.19 s | 2 | details |
#8 | RUNTIME ERROR | 0.19 s | 2 | details |
#9 | RUNTIME ERROR | 0.20 s | 2 | details |
#10 | RUNTIME ERROR | 0.18 s | 2 | details |
#11 | RUNTIME ERROR | 0.19 s | 3 | details |
#12 | RUNTIME ERROR | 0.19 s | 3 | details |
#13 | RUNTIME ERROR | 0.18 s | 3 | details |
#14 | RUNTIME ERROR | 0.19 s | 3 | details |
#15 | RUNTIME ERROR | 0.18 s | 3 | details |
Code
import java.util.Scanner; public class K19_2_5_Ruudukko { static int k; public static void main(String[] args) { Scanner s = new Scanner(System.in); k = Integer.parseInt(s.nextLine()); s.close(); char[][] board = new char[20][20]; for (int i = 0; i < board.length; i++) { for (int j = 0; j < board[0].length; j++) { board[i][j] = '#'; } } if (k == 0) { printBoard(board); } else { board[0][0] = '.'; printBoard(solve(board, k)); } } private static char[][] solve(char[][] board, int k) { for (int y = 0; y < board.length; y++) { for (int x = 0; x < board[0].length; x++) { if (board[y][x] == '.') { if (k > 1) { if (checkIfPathNotFinished(board, y, x)) { board = splitPath(board, y, x); k = k - 1; } } if (checkIfPathNotFinished(board, y, x)) { board = addTile(board, y, x); } } } } return board; } private static char[][] splitPath(char[][] board, int y, int x) { int y1 = y < 19 ? y + 1 : y; int x1 = x < 19 ? x + 1 : x; // 2 to the right board[y][x1] = '.'; board[y][x1 + 1] = '.'; // 2 down board[y1][x] = '.'; board[y1 + 1][x] = '.'; //printBoard(board); return board; } private static char[][] addTile(char[][] board, int y, int x) { if (x + 1 < 19 && x + 2 != '.') { board[y][x+1] = '.'; } else if (x == 18 ) { board[y][x+1] = '.'; } else if (y < 19) { board[y+1][x] = '.'; } //printBoard(board); return board; } private static boolean checkIfPathNotFinished(char[][] board, int y, int x) { if (x == 19) { if (y == 19) return false; if (board[y+1][x] == '#') { return true; } } if (y == 19) { if (x == 19) return false; if (board[y][x + 1] == '#') { return true; } } if (board[y][x + 1] != '.' && board[y + 1][x] != '.') return true; return false; } private static void printBoard(char[][] board) { for (int i = 0; i < board.length; i++) { System.out.println(new String(board[i])); } } }
Test details
Test 1
Group: 1
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
.................... .################### .################### .################### .################### ... |
user output |
---|
.................... .##################. .................... ###################. ###################. ... |
Test 2
Group: 1
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
.................... .################..# .#################.. .#################.. .##################. ... |
user output |
---|
.................... .#.#.#.############. .................... ###################. ###################. ... |
Test 3
Group: 1
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
.................... .################..# .#################.. .#################.. .##################. ... |
user output |
---|
.................... .#.#.#.#.#.########. .................... ###################. ###################. ... |
Test 4
Group: 1
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
.................... .################### .################### .################### .################### ... |
user output |
---|
.................... .#.#.#.#.#.#.######. .................... ###################. ###################. ... |
Test 5
Group: 1
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
.................... .################### .################### .################### .################### ... |
user output |
---|
.................... .#.#.#.#.#.#.#.####. .................... ###################. ###################. ... |
Test 6
Group: 2
Verdict: RUNTIME ERROR
input |
---|
19 |
correct output |
---|
.................... .############..##### .#############..#### .#############...### .##############...## ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 7
Group: 2
Verdict: RUNTIME ERROR
input |
---|
32 |
correct output |
---|
.................... .################### .################### .################### .################### ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 8
Group: 2
Verdict: RUNTIME ERROR
input |
---|
44 |
correct output |
---|
.................... .################..# .#################.. .#################.. .##################. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 9
Group: 2
Verdict: RUNTIME ERROR
input |
---|
76 |
correct output |
---|
.................... .########..######..# .#########..######.. .#########...#####.. .##########...#####. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 10
Group: 2
Verdict: RUNTIME ERROR
input |
---|
93 |
correct output |
---|
.................... .########..##..##..# .#########..##..##.. .#########...#...#.. .##########...#...#. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 11
Group: 3
Verdict: RUNTIME ERROR
input |
---|
141 |
correct output |
---|
.................... .################..# .#################.. .#################.. .##################. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 12
Group: 3
Verdict: RUNTIME ERROR
input |
---|
422 |
correct output |
---|
.................... .####..##########..# .#####..##########.. .#####...#########.. .######...#########. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 13
Group: 3
Verdict: RUNTIME ERROR
input |
---|
671 |
correct output |
---|
.................... .#.##########..##..# ....##########..##.. .#...#########...#.. .##...#########...#. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 14
Group: 3
Verdict: RUNTIME ERROR
input |
---|
895 |
correct output |
---|
.................... .#.##..##..##..##..# ....##..##..##..##.. .#...#...#...#...#.. .##...#...#...#...#. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)
Test 15
Group: 3
Verdict: RUNTIME ERROR
input |
---|
956 |
correct output |
---|
.................... .#.##..######..##..# ....##..######..##.. .#...#...#####...#.. .##...#...#####...#. ... |
user output |
---|
(empty) |
Error:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 20 out of bounds for length 20 at K19_2_5_Ruudukko.splitPath(K19_2_5_Ruudukko.java:51) at K19_2_5_Ruudukko.solve(K19_2_5_Ruudukko.java:31) at K19_2_5_Ruudukko.main(K19_2_5_Ruudukko.java:21)