結果

問題 No.2958 Placing Many L-s
ユーザー hiro1729hiro1729
提出日時 2024-11-08 22:09:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 3,284 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 79,360 KB
最終ジャッジ日時 2024-11-08 22:09:55
合計ジャッジ時間 5,320 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,120 KB
testcase_01 AC 41 ms
52,608 KB
testcase_02 AC 42 ms
53,632 KB
testcase_03 AC 102 ms
78,208 KB
testcase_04 AC 90 ms
78,208 KB
testcase_05 AC 86 ms
78,336 KB
testcase_06 AC 44 ms
52,992 KB
testcase_07 AC 76 ms
73,856 KB
testcase_08 AC 43 ms
54,016 KB
testcase_09 AC 81 ms
76,288 KB
testcase_10 AC 71 ms
72,576 KB
testcase_11 AC 101 ms
76,928 KB
testcase_12 AC 72 ms
74,112 KB
testcase_13 AC 83 ms
76,160 KB
testcase_14 AC 92 ms
76,416 KB
testcase_15 AC 129 ms
77,056 KB
testcase_16 AC 81 ms
76,544 KB
testcase_17 AC 101 ms
76,672 KB
testcase_18 AC 38 ms
52,992 KB
testcase_19 AC 84 ms
78,080 KB
testcase_20 AC 86 ms
78,080 KB
testcase_21 AC 37 ms
52,992 KB
testcase_22 AC 86 ms
78,208 KB
testcase_23 AC 39 ms
52,864 KB
testcase_24 AC 145 ms
77,056 KB
testcase_25 AC 124 ms
77,440 KB
testcase_26 AC 138 ms
78,208 KB
testcase_27 AC 135 ms
77,480 KB
testcase_28 AC 145 ms
79,360 KB
testcase_29 AC 86 ms
76,032 KB
testcase_30 AC 53 ms
60,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

for _ in range(int(input())):
	N, M = map(int, input().split())
	if N >= 3 and N % 2 == 1 and M % 8 == 0:
		print(N * M // 4)
		ans = [[0] * M for _ in range(N)]
		c = 1
		for i in range(0, N - 3, 2):
			for j in range(0, M, 4):
				ans[i][j] = c
				ans[i][j + 1] = c
				ans[i][j + 2] = c
				ans[i][j + 3] = c + 1
				ans[i + 1][j] = c
				ans[i + 1][j + 1] = c + 1
				ans[i + 1][j + 2] = c + 1
				ans[i + 1][j + 3] = c + 1
				c += 2
		for j in range(0, M, 8):
			ans[N - 3][j] = c
			ans[N - 3][j + 1] = c + 1
			ans[N - 3][j + 2] = c + 1
			ans[N - 3][j + 3] = c + 1
			ans[N - 3][j + 4] = c + 2
			ans[N - 3][j + 5] = c + 2
			ans[N - 3][j + 6] = c + 2
			ans[N - 3][j + 7] = c + 3
			ans[N - 2][j] = c
			ans[N - 2][j + 1] = c + 1
			ans[N - 2][j + 2] = c + 4
			ans[N - 2][j + 3] = c + 5
			ans[N - 2][j + 4] = c + 5
			ans[N - 2][j + 5] = c + 5
			ans[N - 2][j + 6] = c + 2
			ans[N - 2][j + 7] = c + 3
			ans[N - 1][j] = c
			ans[N - 1][j + 1] = c
			ans[N - 1][j + 2] = c + 4
			ans[N - 1][j + 3] = c + 4
			ans[N - 1][j + 4] = c + 4
			ans[N - 1][j + 5] = c + 5
			ans[N - 1][j + 6] = c + 3
			ans[N - 1][j + 7] = c + 3
			c += 6
		for i in range(N):
			print(*ans[i])
		continue
	if M >= 3 and M % 2 == 1 and N % 8 == 0:
		print(N * M // 4)
		ans = [[0] * M for _ in range(N)]
		c = 1
		for i in range(0, N, 4):
			for j in range(0, M - 3, 2):
				ans[i][j] = c
				ans[i][j + 1] = c
				ans[i + 1][j] = c
				ans[i + 1][j + 1] = c + 1
				ans[i + 2][j] = c
				ans[i + 2][j + 1] = c + 1
				ans[i + 3][j] = c + 1
				ans[i + 3][j + 1] = c + 1
				c += 2
		for i in range(0, N, 8):
			ans[i][M - 3] = c
			ans[i][M - 2] = c
			ans[i][M - 1] = c
			ans[i + 1][M - 3] = c
			ans[i + 1][M - 2] = c + 1
			ans[i + 1][M - 1] = c + 1
			ans[i + 2][M - 3] = c + 4
			ans[i + 2][M - 2] = c + 4
			ans[i + 2][M - 1] = c + 1
			ans[i + 3][M - 3] = c + 4
			ans[i + 3][M - 2] = c + 5
			ans[i + 3][M - 1] = c + 1
			ans[i + 4][M - 3] = c + 4
			ans[i + 4][M - 2] = c + 5
			ans[i + 4][M - 1] = c + 2
			ans[i + 5][M - 3] = c + 5
			ans[i + 5][M - 2] = c + 5
			ans[i + 5][M - 1] = c + 2
			ans[i + 6][M - 3] = c + 3
			ans[i + 6][M - 2] = c + 2
			ans[i + 6][M - 1] = c + 2
			ans[i + 7][M - 3] = c + 3
			ans[i + 7][M - 2] = c + 3
			ans[i + 7][M - 1] = c + 3
			c += 6
		for i in range(N):
			print(*ans[i])
		continue
	if N % 4 == 0 and M % 2 == 0:
		print(N * M // 4)
		ans = [[0] * M for _ in range(N)]
		c = 1
		for i in range(N // 4):
			for j in range(M // 2):
				ans[4 * i][2 * j] = c
				ans[4 * i][2 * j + 1] = c
				ans[4 * i + 1][2 * j] = c
				ans[4 * i + 1][2 * j + 1] = c + 1
				ans[4 * i + 2][2 * j] = c
				ans[4 * i + 2][2 * j + 1] = c + 1
				ans[4 * i + 3][2 * j] = c + 1
				ans[4 * i + 3][2 * j + 1] = c + 1
				c += 2
		for i in range(N):
			print(*ans[i])
		continue
	elif N % 2 == 0 and M % 4 == 0:
		print(N * M // 4)
		ans = [[0] * M for _ in range(N)]
		c = 1
		for i in range(N // 2):
			for j in range(M // 4):
				ans[2 * i][4 * j] = c
				ans[2 * i + 1][4 * j] = c
				ans[2 * i][4 * j + 1] = c
				ans[2 * i + 1][4 * j + 1] = c + 1
				ans[2 * i][4 * j + 2] = c
				ans[2 * i + 1][4 * j + 2] = c + 1
				ans[2 * i][4 * j + 3] = c + 1
				ans[2 * i + 1][4 * j + 3] = c + 1
				c += 2
		for i in range(N):
			print(*ans[i])
		continue
	print(-1)
0