結果
| 問題 | No.2509 Beam Shateki | 
| コンテスト | |
| ユーザー |  rlangevin | 
| 提出日時 | 2023-12-31 01:16:35 | 
| 言語 | PyPy3 (7.3.15) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 1,082 ms / 2,000 ms | 
| コード長 | 1,559 bytes | 
| コンパイル時間 | 635 ms | 
| コンパイル使用メモリ | 82,584 KB | 
| 実行使用メモリ | 79,096 KB | 
| 最終ジャッジ日時 | 2024-09-27 16:59:43 | 
| 合計ジャッジ時間 | 33,301 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 61 | 
ソースコード
H, W = map(int, input().split())
A = []
for i in range(H):
    A.append(list(map(int, input().split())))
    
L = []
for i in range(H):
    for j in range(W):
        if i == 0 or j == W - 1 or j == 0:
            L.append((i, j))
            
dx = [1, 0, 1, 1]
dy = [0, 1, 1, -1]
def f(x1, y1, k1, x2, y2, k2):
    S = set()
    while True:
        S.add(x1*W+y1)
        x1 += dx[k1]
        y1 += dy[k1]
        if x1 < 0 or x1 > H - 1 or y1 < 0 or y1 > W - 1:
            break
    while True:
        S.add(x2*W+y2)
        x2 += dx[k2]
        y2 += dy[k2]
        if x2 < 0 or x2 > H - 1 or y2 < 0 or y2 > W - 1:
            break
    return S
ans = 0
for a in range(len(L)):
    x1, y1 = L[a]
    for k1 in range(4):
        if k1 == 0 and x1 != 0:
            continue
        if k1 == 1 and y1 != 0:
            continue
        if k1 == 2 and y1 == W - 1:
            continue
        if k1 == 3 and y1 == 0:
            continue
        for b in range(a, len(L)):
            x2, y2 = L[b]
            for k2 in range(4):
                if k2 == 0 and x2 != 0:
                    continue
                if k2 == 1 and y2 != 0:
                    continue
                if k2 == 2 and y2 == W - 1:
                    continue
                if k2 == 3 and y2 == 0:
                    continue
                S = f(x1, y1, k1, x2, y2, k2)
                temp = 0
                for v in S:
                    xs, ys = divmod(v, W)
                    temp += A[xs][ys]
                ans = max(ans, temp)
                
print(ans)
            
            
            
        