結果

問題 No.2112 All 2x2 are Equal
ユーザー rlangevinrlangevin
提出日時 2024-03-18 12:23:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 406 ms / 2,000 ms
コード長 1,117 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 269,564 KB
最終ジャッジ日時 2024-03-18 12:24:07
合計ジャッジ時間 13,282 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
55,604 KB
testcase_01 AC 40 ms
55,604 KB
testcase_02 AC 94 ms
79,332 KB
testcase_03 AC 64 ms
75,908 KB
testcase_04 AC 225 ms
164,512 KB
testcase_05 AC 216 ms
174,996 KB
testcase_06 AC 368 ms
269,564 KB
testcase_07 AC 158 ms
122,428 KB
testcase_08 AC 268 ms
218,152 KB
testcase_09 AC 81 ms
83,732 KB
testcase_10 AC 172 ms
141,104 KB
testcase_11 AC 135 ms
108,928 KB
testcase_12 AC 191 ms
128,400 KB
testcase_13 AC 337 ms
251,424 KB
testcase_14 AC 79 ms
81,140 KB
testcase_15 AC 267 ms
200,480 KB
testcase_16 AC 51 ms
64,552 KB
testcase_17 AC 292 ms
217,768 KB
testcase_18 AC 67 ms
75,324 KB
testcase_19 AC 88 ms
84,696 KB
testcase_20 AC 77 ms
79,148 KB
testcase_21 AC 316 ms
233,932 KB
testcase_22 AC 81 ms
81,272 KB
testcase_23 AC 75 ms
79,652 KB
testcase_24 AC 124 ms
88,200 KB
testcase_25 AC 106 ms
93,400 KB
testcase_26 AC 99 ms
90,328 KB
testcase_27 AC 129 ms
107,688 KB
testcase_28 AC 224 ms
173,080 KB
testcase_29 AC 99 ms
85,740 KB
testcase_30 AC 153 ms
122,296 KB
testcase_31 AC 250 ms
184,736 KB
testcase_32 AC 372 ms
256,864 KB
testcase_33 AC 313 ms
248,364 KB
testcase_34 AC 406 ms
256,776 KB
testcase_35 AC 313 ms
248,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import *

def rot90(A):
    # 時計回りに90度回転
    return list(zip(*(A[::-1])))


H, W = map(int, input().split())
flag = 0
if W % 2 == 0:
    flag = 1
    H, W = W, H
    
N = H * W
Q = deque(range(1, N + 1))
ans = [[-1] * W for _ in range(H)]
for i in range(H//2):
    for j in range(W):
        if j % 2 == 0:
            ans[2 * i][j] = Q.popleft()
            ans[2 * i + 1][j] = Q.pop()
        else:
            ans[2 * i][j] = Q.pop()
            ans[2 * i + 1][j] = Q.popleft()
            
s = 0
for i in range(2):
    for j in range(2):
        s += ans[i][j]
        
if H % 2:
    ans[-1][0] = Q.popleft()
    for j in range(1, W):
        ans[-1][j] = s - ans[-1][j - 1] - ans[-2][j] - ans[-2][j - 1]
        
if flag:
    H, W = W, H
    ans = rot90(ans)
        
Sn, Ss = set(), set()
for i in range(H):
    for j in range(W):
        Sn.add(ans[i][j])
        
for i in range(H - 1):
    for j in range(W - 1):
        Ss.add(ans[i][j] + ans[i+1][j] +ans[i][j+1] +ans[i+1][j+1])
        
assert len(Sn) == H * W
assert len(Ss) == 1

print("Yes")
for a in ans:
    print(*a)
0