結果
問題 | No.1434 Make Maze |
ユーザー | ks2m |
提出日時 | 2021-03-19 23:25:35 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 170 ms / 2,000 ms |
コード長 | 3,213 bytes |
コンパイル時間 | 3,007 ms |
コンパイル使用メモリ | 77,604 KB |
実行使用メモリ | 43,416 KB |
最終ジャッジ日時 | 2024-11-24 21:40:55 |
合計ジャッジ時間 | 10,229 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 119 ms
40,968 KB |
testcase_01 | AC | 119 ms
41,580 KB |
testcase_02 | AC | 160 ms
42,880 KB |
testcase_03 | AC | 163 ms
43,416 KB |
testcase_04 | AC | 115 ms
41,160 KB |
testcase_05 | AC | 103 ms
41,040 KB |
testcase_06 | AC | 103 ms
41,108 KB |
testcase_07 | AC | 104 ms
41,496 KB |
testcase_08 | AC | 115 ms
41,176 KB |
testcase_09 | AC | 114 ms
41,296 KB |
testcase_10 | AC | 115 ms
41,552 KB |
testcase_11 | AC | 116 ms
41,028 KB |
testcase_12 | AC | 120 ms
41,276 KB |
testcase_13 | AC | 112 ms
41,700 KB |
testcase_14 | AC | 117 ms
41,328 KB |
testcase_15 | AC | 159 ms
42,036 KB |
testcase_16 | AC | 114 ms
41,820 KB |
testcase_17 | AC | 121 ms
41,420 KB |
testcase_18 | AC | 130 ms
41,216 KB |
testcase_19 | AC | 170 ms
42,376 KB |
testcase_20 | AC | 119 ms
41,580 KB |
testcase_21 | AC | 133 ms
41,964 KB |
testcase_22 | AC | 114 ms
41,180 KB |
testcase_23 | AC | 117 ms
41,240 KB |
testcase_24 | AC | 165 ms
42,240 KB |
testcase_25 | AC | 159 ms
42,616 KB |
testcase_26 | AC | 124 ms
41,592 KB |
testcase_27 | AC | 168 ms
42,368 KB |
testcase_28 | AC | 107 ms
41,064 KB |
testcase_29 | AC | 113 ms
41,068 KB |
testcase_30 | AC | 130 ms
41,268 KB |
testcase_31 | AC | 132 ms
42,016 KB |
ソースコード
import java.io.PrintWriter; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int w = sc.nextInt(); int x = sc.nextInt(); sc.close(); char[][] s = null; if (h % 4 == 3 && w % 4 == 3) { int max = h * (w / 2 + 1) + (w / 2) - 1; if (h % 4 == 3 && w % 4 == 3) { max -= Math.min(h, w) - 1; } if (x <= max) { s = solve(h, w, x); } else { if (h <= w) { int w2 = w - 2; max = h * (w2 / 2 + 1) + (w2 / 2) - 1; char[][] s1 = solve(h, w - 2, max); char[][] s2 = solve(h, 3, x - max + h - 1); if (s2 == null) { System.out.println(-1); return; } s = new char[h][w]; for (int i = 0; i < h; i++) { for (int j = 0; j < w2; j++) { s[i][j] = s1[i][j]; } for (int j = 0; j < 3; j++) { s[i][w2 - 1 + j] = s2[i][j]; } } } else { int h2 = h - 2; max = w * (h2 / 2 + 1) + (h2 / 2) - 1; char[][] s1 = solve(h - 2, w, max); char[][] s2 = solve(3, w, x - max + w - 1); if (s2 == null) { System.out.println(-1); return; } s = new char[h][w]; for (int j = 0; j < w; j++) { for (int i = 0; i < h2; i++) { s[i][j] = s1[i][j]; } for (int i = 0; i < 3; i++) { s[h2 - 1 + i][j] = s2[i][j]; } } } } } else { s = solve(h, w, x); } if (s == null) { System.out.println(-1); return; } PrintWriter pw = new PrintWriter(System.out); for (int i = 0; i < h; i++) { pw.println(s[i]); } pw.flush(); } static char[][] solve(int h, int w, int x) { int min = h + w - 2; int max = h * (w / 2 + 1) + (w / 2) - 1; if (h % 4 == 3 && w % 4 == 3) { max -= Math.min(h, w) - 1; } int y = max - x; if (x < min || max < x || y % 4 != 0) { return null; } y /= 4; char[][] s = new char[h][w]; for (int i = 0; i < h; i++) { Arrays.fill(s[i], '.'); } for (int i = 1; i < h; i += 2) { for (int j = 1; j < w; j += 2) { s[i][j] = '#'; } } boolean tate = true; if (w % 4 == 3) { if (h % 4 == 1 || h > w) { tate = false; } } if (tate) { tate(s, h, w, y); } else { yoko(s, h, w, y); } return s; } static void tate(char[][] s, int h, int w, int y) { for (int j = 1; j < w; j += 4) { s[0][j] = '#'; } for (int i = 2; i < h - 1; i += 2) { for (int j = 1; j < w; j += 2) { s[i][j] = '#'; } } for (int j = 3; j < w; j += 4) { s[h - 1][j] = '#'; } int i = h - 1; int j = 1; for (int k = 0; k < y; k++) { s[i][j] = '#'; s[i - 2][j] = '.'; i -= 2; if (i < 2) { i = h - 1; j += 4; } } } static void yoko(char[][] s, int h, int w, int y) { for (int i = 1; i < h; i += 4) { s[i][0] = '#'; } for (int j = 2; j < w - 1; j += 2) { for (int i = 1; i < h; i += 2) { s[i][j] = '#'; } } for (int i = 3; i < h; i += 4) { s[i][w - 1] = '#'; } int j = w - 1; int i = 1; for (int k = 0; k < y; k++) { s[i][j] = '#'; s[i][j - 2] = '.'; j -= 2; if (j < 2) { j = w - 1; i += 4; } } } }