結果

問題 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
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 61
権限があれば一括ダウンロードができます

ソースコード

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)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0