結果

問題 No.2509 Beam Shateki
ユーザー lloyz
提出日時 2023-12-29 21:16:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 1,648 bytes
コンパイル時間 1,464 ms
コンパイル使用メモリ 82,436 KB
実行使用メモリ 78,020 KB
最終ジャッジ日時 2024-09-27 16:21:01
合計ジャッジ時間 9,187 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict

h, w = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(h)]

T = defaultdict(int)
Y = defaultdict(int)
P = defaultdict(int)
M = defaultdict(int)
for i in range(h):
    for j in range(w):
        T[i] += A[i][j]
        Y[j] += A[i][j]
        P[i + j] += A[i][j]
        M[i - j] += A[i][j]

ans = 0
L = [T, Y, P, M]
for C in L:
    for i in C:
        for j in C:
            if i == j:
                continue
            ans = max(ans, C[i] + C[j])
for i in T:
    for j in Y:
        ans = max(ans, T[i] + Y[j] - A[i][j])
for i in T:
    for j in P:
        x = i
        y = j - i
        if 0 <= y < w:
            ans = max(ans, T[i] + P[j] - A[x][y])
        else:
            ans = max(ans, T[i] + P[j])
for i in T:
    for j in M:
        x = i
        y = i - j
        if 0 <= y < w:
            ans = max(ans, T[i] + M[j] - A[x][y])
        else:
            ans = max(ans, T[i] + M[j])
for i in Y:
    for j in P:
        x = j - i
        y = i
        if 0 <= x < h:
            ans = max(ans, Y[i] + P[j] - A[x][y])
        else:
            ans = max(ans, Y[i] + P[j])
for i in Y:
    for j in M:
        x = i + j
        y = i
        if 0 <= x < h:
            ans = max(ans, Y[i] + M[j] - A[x][y])
        else:
            ans = max(ans, Y[i] + M[j])
for i in P:
    for j in M:
        x = (i + j) / 2
        y = (i - j) / 2
        if int(x) == x and int(y) == y and 0 <= x < h and 0 <= y < w:
            x = int(x)
            y = int(y)
            ans = max(ans, P[i] + M[j] - A[x][y])
        else:
            ans = max(ans, P[i] + M[j])
print(ans)
0