結果

問題 No.2509 Beam Shateki
ユーザー 👑 timitimi
提出日時 2023-10-28 04:30:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 105 ms / 2,000 ms
コード長 1,405 bytes
コンパイル時間 260 ms
コンパイル使用メモリ 81,768 KB
実行使用メモリ 76,704 KB
最終ジャッジ日時 2023-10-28 04:31:04
合計ジャッジ時間 7,732 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,524 KB
testcase_01 AC 39 ms
53,524 KB
testcase_02 AC 38 ms
53,524 KB
testcase_03 AC 91 ms
76,168 KB
testcase_04 AC 95 ms
76,172 KB
testcase_05 AC 93 ms
76,168 KB
testcase_06 AC 91 ms
76,168 KB
testcase_07 AC 92 ms
76,172 KB
testcase_08 AC 90 ms
76,172 KB
testcase_09 AC 92 ms
76,168 KB
testcase_10 AC 91 ms
76,172 KB
testcase_11 AC 91 ms
76,168 KB
testcase_12 AC 92 ms
76,172 KB
testcase_13 AC 102 ms
76,292 KB
testcase_14 AC 103 ms
76,300 KB
testcase_15 AC 103 ms
76,292 KB
testcase_16 AC 105 ms
76,292 KB
testcase_17 AC 101 ms
76,292 KB
testcase_18 AC 101 ms
76,292 KB
testcase_19 AC 100 ms
76,300 KB
testcase_20 AC 101 ms
76,300 KB
testcase_21 AC 102 ms
76,288 KB
testcase_22 AC 101 ms
76,292 KB
testcase_23 AC 104 ms
76,292 KB
testcase_24 AC 104 ms
76,292 KB
testcase_25 AC 104 ms
76,300 KB
testcase_26 AC 104 ms
76,292 KB
testcase_27 AC 103 ms
76,300 KB
testcase_28 AC 103 ms
76,292 KB
testcase_29 AC 104 ms
76,292 KB
testcase_30 AC 103 ms
76,292 KB
testcase_31 AC 102 ms
76,288 KB
testcase_32 AC 103 ms
76,300 KB
testcase_33 AC 57 ms
66,124 KB
testcase_34 AC 97 ms
76,284 KB
testcase_35 AC 101 ms
76,368 KB
testcase_36 AC 86 ms
76,104 KB
testcase_37 AC 58 ms
66,384 KB
testcase_38 AC 88 ms
76,108 KB
testcase_39 AC 94 ms
76,492 KB
testcase_40 AC 104 ms
76,704 KB
testcase_41 AC 40 ms
53,524 KB
testcase_42 AC 88 ms
76,024 KB
testcase_43 AC 100 ms
76,256 KB
testcase_44 AC 101 ms
76,252 KB
testcase_45 AC 89 ms
76,104 KB
testcase_46 AC 88 ms
76,032 KB
testcase_47 AC 100 ms
76,244 KB
testcase_48 AC 97 ms
76,324 KB
testcase_49 AC 98 ms
76,308 KB
testcase_50 AC 97 ms
76,304 KB
testcase_51 AC 60 ms
66,112 KB
testcase_52 AC 98 ms
76,324 KB
testcase_53 AC 39 ms
53,524 KB
testcase_54 AC 39 ms
53,524 KB
testcase_55 AC 38 ms
53,524 KB
testcase_56 AC 39 ms
53,524 KB
testcase_57 AC 40 ms
53,524 KB
testcase_58 AC 39 ms
53,524 KB
testcase_59 AC 39 ms
53,524 KB
testcase_60 AC 39 ms
53,524 KB
testcase_61 AC 40 ms
53,524 KB
testcase_62 AC 39 ms
53,524 KB
testcase_63 AC 40 ms
53,524 KB
権限があれば一括ダウンロードができます

ソースコード

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];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)
0