結果

問題 No.2509 Beam Shateki
ユーザー loop0919loop0919
提出日時 2023-10-20 22:55:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 2,217 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 77,444 KB
最終ジャッジ日時 2024-09-20 21:11:47
合計ジャッジ時間 8,545 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 39 ms
52,096 KB
testcase_03 AC 115 ms
77,320 KB
testcase_04 AC 114 ms
77,256 KB
testcase_05 AC 116 ms
77,192 KB
testcase_06 AC 114 ms
77,372 KB
testcase_07 AC 114 ms
77,116 KB
testcase_08 AC 116 ms
77,392 KB
testcase_09 AC 116 ms
77,200 KB
testcase_10 AC 113 ms
77,236 KB
testcase_11 AC 113 ms
77,128 KB
testcase_12 AC 114 ms
77,004 KB
testcase_13 AC 123 ms
77,308 KB
testcase_14 AC 120 ms
77,396 KB
testcase_15 AC 123 ms
77,052 KB
testcase_16 AC 125 ms
77,256 KB
testcase_17 AC 122 ms
77,160 KB
testcase_18 AC 123 ms
77,228 KB
testcase_19 AC 123 ms
77,176 KB
testcase_20 AC 120 ms
77,172 KB
testcase_21 AC 126 ms
77,120 KB
testcase_22 AC 121 ms
77,060 KB
testcase_23 AC 122 ms
77,180 KB
testcase_24 AC 122 ms
77,156 KB
testcase_25 AC 122 ms
77,380 KB
testcase_26 AC 120 ms
77,432 KB
testcase_27 AC 120 ms
77,384 KB
testcase_28 AC 123 ms
77,244 KB
testcase_29 AC 119 ms
77,444 KB
testcase_30 AC 122 ms
77,352 KB
testcase_31 AC 123 ms
77,308 KB
testcase_32 AC 120 ms
77,304 KB
testcase_33 AC 70 ms
70,784 KB
testcase_34 AC 115 ms
77,072 KB
testcase_35 AC 119 ms
77,300 KB
testcase_36 AC 101 ms
76,680 KB
testcase_37 AC 73 ms
71,936 KB
testcase_38 AC 104 ms
76,596 KB
testcase_39 AC 100 ms
76,588 KB
testcase_40 AC 114 ms
77,096 KB
testcase_41 AC 41 ms
53,888 KB
testcase_42 AC 103 ms
76,440 KB
testcase_43 AC 117 ms
77,292 KB
testcase_44 AC 124 ms
77,188 KB
testcase_45 AC 101 ms
76,528 KB
testcase_46 AC 104 ms
76,620 KB
testcase_47 AC 117 ms
77,136 KB
testcase_48 AC 112 ms
77,176 KB
testcase_49 AC 117 ms
77,092 KB
testcase_50 AC 118 ms
76,956 KB
testcase_51 AC 72 ms
70,528 KB
testcase_52 AC 114 ms
77,200 KB
testcase_53 AC 37 ms
52,480 KB
testcase_54 AC 38 ms
52,532 KB
testcase_55 AC 38 ms
52,608 KB
testcase_56 AC 38 ms
53,000 KB
testcase_57 AC 38 ms
52,608 KB
testcase_58 AC 37 ms
52,480 KB
testcase_59 AC 36 ms
52,992 KB
testcase_60 AC 36 ms
52,992 KB
testcase_61 AC 36 ms
52,736 KB
testcase_62 AC 40 ms
52,736 KB
testcase_63 AC 39 ms
52,608 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, input().split())
A = []

for i in range(H):
    A.append(list(map(int, input().split())))

# 横方向
row_sum = []
for i in range(H):
    row_sum.append(sum(A[i]))

# 縦方向
col_sum = []
for j in range(W):
    col_sum.append(sum(a[j] for a in A))

# 斜め↘方向
down_sum = dict()
for x in range(-W+1, H):
    down_sum[x] = 0
    for i in range(H):
        if not 0 <= i - x < W:
            continue
        down_sum[x] += A[i][i-x]

# 斜め↗方向
up_sum = dict()
for x in range(0, H+W-1):
    up_sum[x] = 0
    for i in range(H):
        if not 0 <= x - i < W:
            continue
        up_sum[x] += A[i][x-i]

max_ans = 0

for i in range(H):
    for j in range(i+1, H):
        max_ans = max(max_ans, row_sum[i] + row_sum[j])

for i in range(W):
    for j in range(i+1, W):
        max_ans = max(max_ans, col_sum[i] + col_sum[j])

for k_i, v_i in down_sum.items():
    for k_j, v_j in down_sum.items():
        if k_i == k_j:
            continue
        max_ans = max(max_ans, v_i + v_j)

for k_i, v_i in up_sum.items():
    for k_j, v_j in up_sum.items():
        if k_i == k_j:
            continue
        max_ans = max(max_ans, v_i + v_j)

for i in range(H):
    for j in range(W):
        max_ans = max(max_ans, row_sum[i] + col_sum[j] - A[i][j])

for i in range(H):
    for k, v in down_sum.items():
        sub = A[i][i-k] if 0 <= i-k < W else 0
        max_ans = max(max_ans, row_sum[i] + v - sub)

for i in range(H):
    for k, v in up_sum.items():
        sub = A[i][k-i] if 0 <= k-i < W else 0
        max_ans = max(max_ans, row_sum[i] + v - sub)

for j in range(W):
    for k, v in down_sum.items():
        sub = A[k+j][j] if 0 <= j+k < H else 0
        max_ans = max(max_ans, col_sum[j] + v - sub)

for j in range(W):
    for k, v in up_sum.items():
        sub = A[k-j][j] if 0 <= k-j < H else 0
        max_ans = max(max_ans, col_sum[j] + v - sub)

for k_d, v_d in down_sum.items():
    for k_u, v_u in up_sum.items():
        if (k_d + k_u) % 2 == 0 and 0 <= (k_d + k_u) // 2 < H and 0 <= (-k_d + k_u) // 2 < W:
            sub = A[(k_d + k_u) // 2][(-k_d + k_u) // 2]
        else:
            sub = 0
        max_ans = max(max_ans, v_d + v_u - sub)

print(max_ans)
0