結果

問題 No.1974 2x2 Flipper
ユーザー lam6er
提出日時 2025-04-16 15:33:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 936 bytes
コンパイル時間 273 ms
コンパイル使用メモリ 81,924 KB
実行使用メモリ 83,836 KB
最終ジャッジ日時 2025-04-16 15:38:03
合計ジャッジ時間 5,333 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 20 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())

ans = 0
grid = []

if H % 2 == 0 and W % 2 == 0:
    ans = H * W
    grid = [[1] * W for _ in range(H)]
elif H % 2 == 0 and W % 2 == 1:
    ans = H * (W - 1)
    grid = [[1 if j < W - 1 else 0 for j in range(W)] for _ in range(H)]
elif H % 2 == 1 and W % 2 == 0:
    ans = (H - 1) * W
    grid = [[1] * W for _ in range(H - 1)] + [[0] * W]
else:
    # Both H and W are odd
    ans = (H - 1) * (W - 1) + (H - 1) + (W - 1) - 2
    grid = [[0] * W for _ in range(H)]
    # Fill first H-1 rows and W-1 columns
    for i in range(H - 1):
        for j in range(W - 1):
            grid[i][j] = 1
    # Fill last row's first W-1 cells
    for j in range(W - 1):
        grid[H-1][j] = 1
    # Fill last column's first H-1 cells
    for i in range(H - 1):
        grid[i][W-1] = 1
    # Ensure the bottom-right corner is 0
    grid[H-1][W-1] = 0

print(ans)
for row in grid:
    print(' '.join(map(str, row)))
0