CSES - KILO 2019 2/5 - Results
Submission details
Task:Ruudukko
Sender:odporkka
Submission time:2019-05-30 22:36:43 +0300
Language:Java
Status:READY
Result:12
Feedback
groupverdictscore
#1ACCEPTED12
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.18 s1details
#2ACCEPTED0.18 s1details
#3ACCEPTED0.18 s1details
#4ACCEPTED0.19 s1details
#5ACCEPTED0.18 s1details
#60.18 s2details
#70.19 s2details
#80.19 s2details
#90.20 s2details
#100.18 s2details
#110.19 s3details
#120.19 s3details
#130.18 s3details
#140.19 s3details
#150.18 s3details

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:

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:

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:

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:

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:

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:

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:

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:

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:

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:

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)