結果
| 問題 |
No.2509 Beam Shateki
|
| コンテスト | |
| ユーザー |
timi
|
| 提出日時 | 2023-10-28 04:30:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 103 ms / 2,000 ms |
| コード長 | 1,405 bytes |
| コンパイル時間 | 231 ms |
| コンパイル使用メモリ | 81,828 KB |
| 実行使用メモリ | 77,252 KB |
| 最終ジャッジ日時 | 2024-09-25 16:04:12 |
| 合計ジャッジ時間 | 6,912 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 61 |
ソースコード
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];DDD=sorted(DD)[::-1];EEE=sorted(EE)[::-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,DDD[0]+DDD[1])
if len(EE)>1:
ans=max(ans,EEE[0]+EEE[1])
for d in D:
for e in E:
if (d+e)%2==0 and (d-e)%2==0:
x,y=(d+e)//2,(d-e)//2
if 0<=x<H and 0<=y<W:
f=1
else:
ans=max(ans,D[d]+E[e])
else:
ans=max(ans,D[d]+E[e])
for h in range(H):
if 0<=d-h<W:
f=1
else:
ans=max(ans,D[d]+B[h])
for w in range(W):
if 0<=d-w<H:
f=1
else:
ans=max(ans,D[d]+C[w])
for e in E:
for h in range(H):
if 0<=h-e<W:
f=1
else:
ans=max(ans,E[e]+B[h])
for w in range(W):
if 0<=e+w<H:
f=1
else:
ans=max(ans,E[e]+C[w])
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)
timi