結果

問題 No.1974 2x2 Flipper
ユーザー minimumminimum
提出日時 2022-06-10 22:59:04
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 1,001 bytes
コンパイル時間 848 ms
コンパイル使用メモリ 81,608 KB
実行使用メモリ 85,096 KB
最終ジャッジ日時 2023-10-21 06:01:03
合計ジャッジ時間 5,879 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,392 KB
testcase_01 AC 69 ms
75,412 KB
testcase_02 AC 55 ms
62,036 KB
testcase_03 AC 112 ms
76,372 KB
testcase_04 AC 81 ms
75,844 KB
testcase_05 AC 78 ms
78,500 KB
testcase_06 AC 96 ms
76,024 KB
testcase_07 AC 83 ms
75,740 KB
testcase_08 AC 56 ms
72,532 KB
testcase_09 AC 97 ms
75,992 KB
testcase_10 AC 59 ms
72,776 KB
testcase_11 AC 87 ms
75,808 KB
testcase_12 AC 112 ms
76,472 KB
testcase_13 AC 91 ms
75,856 KB
testcase_14 AC 77 ms
75,432 KB
testcase_15 AC 123 ms
76,796 KB
testcase_16 AC 71 ms
76,684 KB
testcase_17 AC 102 ms
76,280 KB
testcase_18 AC 56 ms
72,076 KB
testcase_19 AC 63 ms
75,424 KB
testcase_20 AC 82 ms
75,624 KB
testcase_21 AC 141 ms
77,104 KB
testcase_22 AC 141 ms
77,028 KB
testcase_23 AC 143 ms
77,124 KB
testcase_24 AC 160 ms
85,096 KB
testcase_25 AC 38 ms
53,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

if H % 2 == 0 and W % 2 == 0:
    print(H * W)
    a = [1] * W
    for _ in range(H):
        print(*a)
elif H % 2 == 0:
    print(H * (W - 1))
    a = [1] * W
    a[0] = 0
    for _ in range(H):
        print(*a)
elif W % 2 == 0:
    print((H - 1) * W)
    a = [0] * W
    print(*a)
    a = [1] * W
    for _ in range(H - 1):
        print(*a)
else:
    mx, mn = max(H, W), min(H, W)
    print(mx * (mn - 1))
    ans = []
    cnt = [1] * mn
    x = (mx - mn) // 2
    for i in range(mn):
        cnt[i] += 2 * (x // mn)
        if i < x % mn:
            cnt[i] += 2
    b = []
    for i in range(mn):
        for j in range(cnt[i]):
            b.append(i)
    for i in range(mx):
        a = [1] * mn
        a[b[i]] = 0
        ans.append(a)
    if H >= W:
        ans2 = ans
    else:
        ans2 = [[0] * W for i in range(H)]
        for i in range(H):
            for j in range(W):
                ans2[i][j] = ans[j][i]
    for a in ans2:
        print(*a)
0