結果

問題 No.2509 Beam Shateki
ユーザー timi
提出日時 2023-10-27 16:53:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 814 bytes
コンパイル時間 340 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 72,428 KB
最終ジャッジ日時 2024-09-25 13:04:48
合計ジャッジ時間 5,221 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 56 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

H,W=map(int,input().split())
A=[]
B=[];C=[0]*W
D,E={},{}
for i in range(H):
  AA=list(map(int, input().split()))
  for j in range(W):
    C[j]+=AA[j]
    x=i+j
    if x not in D:
      D[x]=0
    y=i-j 
    if y not in E:
      E[y]=0
    D[x]+=AA[j];E[y]+=AA[j]
  A.append(AA)
  B.append(sum(AA))
if H==1 and W==1:
  print(AA[0])
  exit()
  
DD,EE=[],[]
for d in D:
  DD.append(D[d])
for e in E:
  EE.append(E[e])
BB=sorted(B)[::-1];CC=sorted(C)[::-1];DD=sorted(D)[::-1];EE=sorted(E)[::-1]
ans=0
if len(BB)>1:
  ans=max(ans,BB[0]+BB[1])
if len(CC)>1:
  ans=max(ans,CC[0]+CC[1])
if len(DD)>1:
  ans=max(ans,DD[0]+DD[1])
if len(EE)>1:
  ans=max(ans,EE[0]+EE[1])

for h in range(H):
  for w in range(W):
    a=A[h][w]
    CC=[B[h],C[w],D[h+w],E[h-w]]
    CC=sorted(CC)[::-1]
    ans=max(ans,CC[0]+CC[1]-a)
print(ans)
0