結果

問題 No.2958 Placing Many L-s
ユーザー hiro1729hiro1729
提出日時 2024-11-08 22:08:40
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 3,273 bytes
コンパイル時間 309 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 80,000 KB
最終ジャッジ日時 2024-11-08 22:08:58
合計ジャッジ時間 6,900 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
53,120 KB
testcase_01 AC 44 ms
52,992 KB
testcase_02 AC 45 ms
53,504 KB
testcase_03 AC 101 ms
78,080 KB
testcase_04 AC 102 ms
78,464 KB
testcase_05 WA -
testcase_06 AC 43 ms
53,248 KB
testcase_07 WA -
testcase_08 AC 49 ms
54,144 KB
testcase_09 AC 91 ms
76,544 KB
testcase_10 AC 92 ms
72,576 KB
testcase_11 AC 114 ms
76,672 KB
testcase_12 WA -
testcase_13 AC 94 ms
76,416 KB
testcase_14 WA -
testcase_15 AC 151 ms
77,440 KB
testcase_16 WA -
testcase_17 AC 99 ms
76,544 KB
testcase_18 AC 44 ms
52,608 KB
testcase_19 WA -
testcase_20 AC 98 ms
77,696 KB
testcase_21 AC 48 ms
52,864 KB
testcase_22 AC 98 ms
78,080 KB
testcase_23 AC 44 ms
52,992 KB
testcase_24 AC 172 ms
77,312 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 158 ms
77,236 KB
testcase_28 WA -
testcase_29 AC 92 ms
76,032 KB
testcase_30 AC 56 ms
60,544 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
		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