Rezultati

Up. imeNalogaJezikRezultatČas oddaje
scoreoutofboundsexception-2019 Tlakovanje Java 100/100OK 09. maj '19 @ 20:02

Test Točke Porabljen spomin Porabljen čas Status
#1 [več] 5/5 37,070 MiB 0,000 s OK
#2 [več] 5/5 34,754 MiB 0,000 s OK
#3 [več] 6/6 33,051 MiB 0,000 s OK
#4 [več] 6/6 38,848 MiB 0,000 s OK
#5 [več] 6/6 36,633 MiB 0,000 s OK
#6 [več] 6/6 33,027 MiB 0,000 s OK
#7 [več] 6/6 40,152 MiB 0,000 s OK
#8 [več] 6/6 37,117 MiB 0,000 s OK
#9 [več] 6/6 38,016 MiB 0,000 s OK
#10 [več] 6/6 40,945 MiB 0,000 s OK
#11 [več] 6/6 36,621 MiB 0,000 s OK
#12 [več] 6/6 36,715 MiB 0,000 s OK
#13 [več] 6/6 36,785 MiB 0,000 s OK
#14 [več] 6/6 34,184 MiB 0,000 s OK
#15 [več] 6/6 41,391 MiB 0,000 s OK
#16 [več] 6/6 37,512 MiB 0,000 s OK
#17 [več] 6/6 34,008 MiB 0,000 s OK

Ocenjevani program (pica.java):
import java.io.*;
import java.util.*;

public class pica {
	static PrintWriter out = new PrintWriter(System.out);

	public static void sestVodoravno(char[][] ans, int pa, int pb) {
		boolean[] zasedeno = new boolean[20];
		if (pa > 0) {
			for (int b = Math.max(0, pb - 1); b < Math.min(ans[0].length, pb + 4); b++) {
				zasedeno[ans[pa - 1][b] - 'A'] = true;
			}
		}
		if (pa < ans.length - 2) {
			for (int b = Math.max(0, pb - 1); b < Math.min(ans[0].length, pb + 4); b++) {
				zasedeno[ans[pa + 2][b] - 'A'] = true;
			}
		}
		if (pb > 0) {
			zasedeno[ans[pa][pb - 1] - 'A'] = true;
		}
		if (pa < ans.length - 1 && pb > 0) {
			zasedeno[ans[pa + 1][pb - 1] - 'A'] = true;
		}
		if (pb + 3 < ans[0].length) {
			zasedeno[ans[pa][pb + 3] - 'A'] = true;
		}
		if (pa < ans.length - 1 && pb + 3 < ans[0].length) {
			zasedeno[ans[pa + 1][pb + 3] - 'A'] = true;
		}
		for (int i = 0; i < zasedeno.length; i++) {
			if (!zasedeno[i]) {
				ans[pa][pb] = (char) ('A' + i);
				ans[pa + 1][pb] = (char) ('A' + i);
				ans[pa][pb + 1] = (char) ('A' + i);
				zasedeno[i] = true;
				break;
			}
		}
		for (int i = 0; i < zasedeno.length; i++) {
			if (!zasedeno[i]) {
				ans[pa][pb + 2] = (char) ('A' + i);
				ans[pa + 1][pb + 1] = (char) ('A' + i);
				ans[pa + 1][pb + 2] = (char) ('A' + i);
				break;
			}
		}
	}

	public static void sestNavpicno(char[][] ans, int pa, int pb) {
		boolean[] zasedeno = new boolean[20];
		if (pb > 0) {
			for (int b = Math.max(0, pa - 1); b < Math.min(ans.length, pa + 4); b++) {
				zasedeno[ans[b][pb - 1] - 'A'] = true;
			}
		}
		if (pb + 2 < ans[0].length) {
			for (int b = Math.max(0, pa - 1); b < Math.min(ans.length, pa + 4); b++) {
				zasedeno[ans[b][pb + 2] - 'A'] = true;
			}
		}
		if (pa > 0) {
			zasedeno[ans[pa - 1][pb] - 'A'] = true;
		}
		if (pa + 3 < ans.length) {
			zasedeno[ans[pa + 3][pb] - 'A'] = true;
		}
		if (pa > 0 && pb + 1 < ans[0].length) {
			zasedeno[ans[pa - 1][pb + 1] - 'A'] = true;
		}
		if (pa + 3 < ans.length && pb + 1 < ans[0].length) {
			zasedeno[ans[pa + 3][pb + 1] - 'A'] = true;
		}
		for (int i = 0; i < zasedeno.length; i++) {
			if (!zasedeno[i]) {
				ans[pa][pb] = (char) ('A' + i);
				ans[pa + 1][pb] = (char) ('A' + i);
				ans[pa][pb + 1] = (char) ('A' + i);
				zasedeno[i] = true;
				break;
			}
		}
		for (int i = 0; i < zasedeno.length; i++) {
			if (!zasedeno[i]) {
				ans[pa + 2][pb] = (char) ('A' + i);
				ans[pa + 2][pb + 1] = (char) ('A' + i);
				ans[pa + 1][pb + 1] = (char) ('A' + i);
				break;
			}
		}
	}

	public static void resiSodo(char[][] ans, int h, int w) {
		for (int px = 0; px + 2 < w; px += 3) {
			for (int py = 0; py + 1 < h; py += 2) {
				sestVodoravno(ans, py, px);
			}
		}
		for (int py = 0; py + 2 < h; py += 3) {
			sestNavpicno(ans, py, w - 2);
		}
		ans[h - 1][w - 2] = 'I';
		ans[h - 2][w - 2] = 'I';
		ans[h - 2][w - 1] = 'I';
	}

	public static void resiSodo2(char[][] ans, int h, int w) {
		for (int x = 0; x + 1 < w; x += 2) {
			for (int y = 0; y + 2 < h; y += 3) {
				sestNavpicno(ans, y, x);
			}
		}
		for (int x = 0; x + 2 < w; x += 3) {
			sestVodoravno(ans, h - 2, x);
		}
		ans[h - 1][w - 2] = 'I';
		ans[h - 2][w - 2] = 'I';
		ans[h - 2][w - 1] = 'I';
	}

	public static void resi3(char[][] ans, int h, int w) {
		int px = w - 5;
		int py = h - 5;
		char[][] q = { { 'J', 'J', 'L', 'L', 'J' }, { 'K', 'J', 'L', 'J', 'J' }, { 'K', 'K', 'J', 'L', 'L' },
				{ 'L', 'J', 'J', 'K', 'L' }, { 'L', 'L', 'K', 'K', 'O' } };
		for (int i = 0; i < 5; i++) {
			for (int j = 0; j < 5; j++) {
				ans[py + i][px + j] = q[i][j];
			}
		}
		for (px = 0; px + 6 < w; px += 3) {
			for (py = 0; py + 6 < h; py += 2) {
				sestVodoravno(ans, py, px);
			}
		}
		px = w - 5;
		for (py = 0; py + 6 < h; py += 2) {
			sestVodoravno(ans, py, px);
		}
		px = w - 2;
		for (py = 0; py + 6 < h; py += 3) {
			sestNavpicno(ans, py, px);
		}
		py = h - 5;
		for (px = 0; px + 6 < w; px += 2) {
			sestNavpicno(ans, py, px);
		}
		py = h - 2;
		for (px = 0; px + 6 < w; px += 3) {
			sestVodoravno(ans, py, px);
		}
	}

	public static void solve(char[][] ans, int h, int w) {
		if (h % 2 == 0 || w % 2 == 0) {
			if (h % 2 == 0) {
				resiSodo(ans, h, w);
			} else {
				resiSodo2(ans, h, w);
			}
		} else {
			resi3(ans, h, w);
		}
	}

	public static void solve2(char[][] ans, int h, int w) {
		solve(ans, h - 2, w - 2);
		for (int px = 0; px + 5 < w; px += 3) {
			sestVodoravno(ans, h - 2, px);
		}
		for (int py = 0; py + 5 < h; py += 3) {
			sestNavpicno(ans, py, w - 2);
		}
		int px = w - 4;
		int py = h - 4;
		ans[py][px + 2] = 'M';
		ans[py][px + 3] = 'M';
		ans[py + 1][px + 1] = 'N';
		ans[py + 1][px + 2] = 'N';
		ans[py + 1][px + 3] = 'M';
		ans[py + 2][px] = 'M';
		ans[py + 2][px + 1] = 'N';
		ans[py + 2][px + 2] = 'P';
		ans[py + 2][px + 3] = 'P';
		ans[py + 3][px] = 'M';
		ans[py + 3][px + 1] = 'M';
		ans[py + 3][px + 2] = 'P';
	}

	public static void print(char[][] q) {
		for (char[] p : q) {
			out.println(new String(p).replace('O', '#'));
		}
	}

	public static void main(String[] args) throws Exception {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		int t= Integer.parseInt(in.readLine());
		for (int i = 0; i < t; i++) {
			StringTokenizer st = new StringTokenizer(in.readLine());
			int h = Integer.parseInt(st.nextToken());
			int w = Integer.parseInt(st.nextToken());
			char[][] ans = new char[h][w];
			for (char[] q : ans) {
				Arrays.fill(q, 'O');
			}
			if (h == 1 && w == 1) {
				out.println('#');
			} else if (h % 3 == 0 || w % 3 == 0 || (h % 3 != w % 3) || (w == 1 && h > 1) || (h == 1 && w > 1)) {
				out.println("NE GRE IN NE GRE!");
			} else if (h % 3 == 2 && w % 3 == 2) {
				solve(ans, h, w);
				print(ans);
			} else if (h % 3 == 1 && w % 3 == 1) {
				solve2(ans, h, w);
				print(ans);
			} else {
				out.println("Napaka pri dimenzijah");
			}
		}
		out.close();
	}

}